|
-
May 1st, 2008, 12:34 PM
#1
Thread Starter
Frenzied Member
Naming new form question
Hi,
I saw a reply that LaVolpe made showing how to create a new form dynamically with the following code:
Code:
Dim newForm As Form
Set newForm = New frmTemplate
' now newForm is a new instance of frmTemplate
This code works fine but I have a question. The form created is named newForm. Is there any way I can assign my own name to the form such as newForm1, newForm2, etc. for each form that it creates?
Thanks!
-
May 1st, 2008, 12:55 PM
#2
Addicted Member
Re: Naming new form question
If you are creating a number of new forms you would probably do better to put them in a collection. In VB6 the name you are using for the form must be set up in the Dim statement so there is no way of dynamically naming each form but if you store the forms in a collection then you can refer to them as cform[1], cform[2] etc.
If you're going to be crazy, you have to get paid for it or else you're going to be locked up. -- Hunter Thompson
-
May 1st, 2008, 01:04 PM
#3
Thread Starter
Frenzied Member
Re: Naming new form question
Thanks for the reply. When you say in a collection, how do I do this? I am declaring the name in the Dim statement as shown above. The form name is newForm. I assume this is just like creating an index of forms? So when I create a new form, how do I know which number it is? Is it autonumbered?
I appreciate the help!
Warren
-
May 1st, 2008, 01:17 PM
#4
Addicted Member
Re: Naming new form question
this first part of code shows just adding the form to the collection. The collection should be a global variable to a form or module or to the entire project:
Code:
public cForms as collection
public sub nameofSub
dim newForm as Form
set newForm = new frmTemplate
cForms.add (newForm)
end sub
then you can retrieve the forms in other functions as shown here:
Code:
public function getForm(byval iFormNum as integer) as frmTemplate
' this function will return the form selected
' iFormNum is the number corresponding to the form in the collection
' form1 = 1, form2 = 2, etc.
set frmTemplate = cForms(iFormNum)
end function
I use this method when I have several forms in one project and the user may have already opened a form. Rather than create a new form I look through the collection for the form. If it is not in the collection then I create a new form and add it to the collection. This prevents my program from creating more than one instance of each form.
If you're going to be crazy, you have to get paid for it or else you're going to be locked up. -- Hunter Thompson
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|