473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unable to declare and check whether MDI Form exist or not ?

Hi,

I've 50 MDI Forms in my project, so trying to create MDI Child Form from
this procedure.
But the problem is, unable to declare as "NewFormName". It gives me an
error. Is there any
other better way. And I would like to check whether the form already exist
or not. ? Or
else what's happening is, it opens many forms as the user clicks. Any ideas
?
Public Sub mCreateForm(ByVal ParentFormName As Form, _
ByVal NewFormName As Form)
Dim oMDIForm As New NewFormName

With oMDIForm
.lblHeader.Text = "Common Parameter - Color"
.MdiParent = ParentFormName
.Show()
.Top = 0
.Left = 0
End With
End Sub

Thanks and Best Regards
ItsMe
Nov 20 '05 #1
11 2705
Cor
Hi ItsMe,
In the way you tell it, it looks like an endless loop in your mouse click
Event.
When there is no more memory to make all those forms you get an error
because there is no more memory I guess.

I hope this helps a little bit,

Cor
Nov 20 '05 #2
Nopes, its not endless loop, i'll be calling this procedue whenever i need
to load a form. So I'm writing this function in a module. I'll be passing
NewFormName, whenever i need to create any form.

Any Comments ?
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader22.wxs.nl...
Hi ItsMe,
In the way you tell it, it looks like an endless loop in your mouse click
Event.
When there is no more memory to make all those forms you get an error
because there is no more memory I guess.

I hope this helps a little bit,

Cor

Nov 20 '05 #3
Cor
It could maybe give some information if you tell us what the error is.
A some error is very wide error.
Nov 20 '05 #4
Cor
Hi Fergus,
So late and so clever, did not look at the code just at the sentence: "on a
user click a lot of forms are created".

Good daynight
Cor
Nov 20 '05 #5
Fergus,

Thank you very much for your valuable comments. But I modified my code and
corrected the mistakes.
But how can I check whether the form has already created or not? Now my code
looks like this :
Public Sub mCreateForm(ByVal ChildForm As Form, ByVal FormHeading As
String, _
ByVal ParentForm As Form)

If Not IsNothing(ChildForm) Then 'This line doesn't really work
need to check whether form is created or not
With ChildForm
.Text = Trim(FormHeading)
.MdiParent = ParentForm
.Show()
.Top = 0
.Left = 0
End With
End If
End Sub
Now what's happeing is, whenever a user clicks on the form load button.
It opens up a MDI Child Form. If the user clicks second time another form is
opening. I want to avoid this, how can i ? Any ideas ??

Regards

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:Ok**************@TK2MSFTNGP12.phx.gbl...
Oh, Its You!!

|| Public Sub mCreateForm(ByVal ParentFormName As Form, _
|| ByVal NewFormName As Form)

^^ NewFormName is a parameter variable.

|| Dim oMDIForm As New NewFormName

^^ NewFormName is a Type

* This can't be the code you're using because it won't compile.

* This will create a Form with the same type as NewFormName:

Dim oMDIForm As Form
oMDIForm = DirectCast (Activator.CreateInstance (NewFormName.GetType),
Form)

* ParentFormName and NewFormName are bad names because the variables aren't names - they're Forms.
* Better is:

Public Sub mCreateForm (ByVal ParentForm As Form, _
ByVal FormType As Type) Dim oMDIForm As Form
oMDIForm = DirectCast (Activator.CreateInstance (FormType), Form)

I'm off to bed. Good night :-)

Regards,
Fergus
MVP [Windows Keyboard, PC Power Switch]

Nov 20 '05 #6
Hi Smee,

Now I'm confused, lol. You have a method called mCreateForm() which
doesn't seem to do any creating! Where does ChildForm come from ? Are you
intending to create the child Form in mCreateForm() ? Can you show the code
for the caller?

You said in your original query that you have 50 Mdi Forms. Is this 50
individual Mdi Form classes, or 50 instances from just a few classes?

The parent Form has an MdiChildren collection. You can go through this.
But it depends what you mean by 'already created'.

Can you tell me more about the Form Load button - when it gets pressed and
what it's supposed to do?

In fact, can you tell me <lots> more about what you're doing because it's
all a bit fuzzy in my mind. ;-)

Regards,
Fergus
Nov 20 '05 #7
hi fergus,

sorry to make you confuse, lol.

this is a caller code (when button pressed to create MDI Child form):

Call mCreateForm(New frmAdmVendor, "Common Parameter - Vendor", Me)

So everytime, i'm creating an instance in the common class. And calling from
the main menu.

So now the problem is if i'm calling more than once, its creating two
different instances (forms). I want to check whether an instance(form)
already exist or not. If i'm able to check then i'll not create, i'll just
move the form to the front. So how do i do that ?

I hope you understand my problem.

Regards
ItsMe

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
Hi Smee,

Now I'm confused, lol. You have a method called mCreateForm() which
doesn't seem to do any creating! Where does ChildForm come from ? Are you
intending to create the child Form in mCreateForm() ? Can you show the code for the caller?

You said in your original query that you have 50 Mdi Forms. Is this 50
individual Mdi Form classes, or 50 instances from just a few classes?

The parent Form has an MdiChildren collection. You can go through this. But it depends what you mean by 'already created'.

Can you tell me more about the Form Load button - when it gets pressed and what it's supposed to do?

In fact, can you tell me <lots> more about what you're doing because it's all a bit fuzzy in my mind. ;-)

Regards,
Fergus

Nov 20 '05 #8
I hope this will help
' Called from Ingredients menu
Private Sub MnuIngredients_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MnuIngredients.Click
Dim FormFound As Boolean = False
Dim oForm As Form

For Each oForm In Me.MdiChildren
If (oForm.Name = "Ingredients") Then 'Check if we already have
this form...
oForm.Activate() ' YES focus on it....
FormFound = True
Exit For 'It's not necessary to continu "for loop"
End If
Next

If Not FormFound Then ' Not found ... Let's create it
Dim frmIngredients As New Ingredients()
frmIngredients.MdiParent = Me
frmIngredients.Show()
End If
End Sub

Francois

"ItsMe" <it*******@yahoo.com> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
hi fergus,
....

Nov 20 '05 #9
Hi Francois,

Nice routine. :-)

Some teachers/programmers say that you should never exit from a routine
except from the end. I don't believe that one, ;-) so I'd have a slightly
shorter version:

' Called from Ingredients menu
Private Sub MnuIngredients_Click(....) Handles MnuIngredients.Click
Dim oForm As Form
'Exit if we already have this form...
For Each oForm In Me.MdiChildren
If oForm.Name = "Ingredients" Then
Return
End If
Next

' Not found ... Let's create it
Dim frmIngredients As New Ingredients()
frmIngredients.MdiParent = Me
frmIngredients.Show()
End Sub

Regards,
Fergus
Nov 20 '05 #10
Hi Fergus

I agree with you!! But many law are made to be broken!!! But I
keep your solution! I've about 15 differents form that I call by the same
manner. So if we did a little math addition, we found that I could save
about 45 lines!!! :)

Thank for your version 1.1 of "Do_not_Open_a_form_two_time!" :)

Have a nice day
Francois

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi Francois,

Nice routine. :-)

Some teachers/programmers say that you should never exit from a routine except from the end. I don't believe that one, ;-) so I'd have a slightly
shorter version:

' Called from Ingredients menu
Private Sub MnuIngredients_Click(....) Handles MnuIngredients.Click
Dim oForm As Form
'Exit if we already have this form...
For Each oForm In Me.MdiChildren
If oForm.Name = "Ingredients" Then
Return
End If
Next

' Not found ... Let's create it
Dim frmIngredients As New Ingredients()
frmIngredients.MdiParent = Me
frmIngredients.Show()
End Sub

Regards,
Fergus

Nov 20 '05 #11
Hi Francois,

Happy to work with you :-))

You can save even more lines by having a common routine.

Regards,
Fergus

<code status="untested">
Private Sub MnuIngredients_Click(....) Handles MnuIngredients.Click
CreateOrActivateForm ("Ingredients", GetType (Ingredients))
End Sub

Private Sub CreateOrActivateForm _
(sHeading As String, oFormType As Type)
Dim oForm As Form
'Exit if we already have this form...
For Each oForm In Me.MdiChildren
If oForm.Name = sHeading Then
oForm.Activate
Return
End If
Next

' Not found ... Let's create it.
oForm = New Activator.CreateInstance (oFormType)
oForm.MdiParent = Me
oForm.Show()
End Sub
</code>
Nov 20 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jim M | last post by:
For about a year and a half now I have been working in Access 2002 at home and converting to Access 2000 for work (I need both versions). I made a few changes to forms and queries then converted to...
7
by: andylcx | last post by:
Hi all: The c++ language can check whether the file exist or not. I am wondering how c language does this job? Thanks a lot! Andy
10
by: robwharram | last post by:
Hi, I'm quite frustrated in the fact that I can't even display a simple "Hello World" message on .Net. I've been through all of the groups and searched all over the place and haven't been able...
1
by: andrew | last post by:
I have a MSchart object (COM Component) which I wish to insert as an image into a picture box so that I can print it out. 'I call the chart controls's EditCopy to pass data to the clipboard. ...
6
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
14
by: Dan | last post by:
Hello, we have an intranet application using Windows Integrated Authentification. When an user starts the application, he gets a form for inputting data. The first time he does that, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.