VB 6.0 Dynamic Form loading? 
Author Message
 VB 6.0 Dynamic Form loading?

Finally, I'm learning enough about VB to have serious questions.

Is there anyway to load a form by deriving its name from a string?

For example, I have Form1, Form2, Form3, etc. Based on user input, I need to
load one to n forms, the number being the differentiator. The following
doesn't work, but it gives the idea of what I'm trying to do:

For i = 1 to n
    load "form" & cstr(i)
next i

This code blows up on the load due to type mismatch. Is there anyway to
effect the result of loading Form1 to FormN based on the setting of N?

Any help would be greatly appreciated.

Cheers,
Palmer King



Sat, 29 Dec 2001 03:00:00 GMT  
 VB 6.0 Dynamic Form loading?
Put your forms in array

frmMyForm(0), frmMyForm(1) etc..

For i = 0 to n
 load frmMyForm(i)
Next i

should work..

Regards
Tim

Quote:

> Finally, I'm learning enough about VB to have serious questions.

> Is there anyway to load a form by deriving its name from a string?

> For example, I have Form1, Form2, Form3, etc. Based on user input, I need to
> load one to n forms, the number being the differentiator. The following
> doesn't work, but it gives the idea of what I'm trying to do:

> For i = 1 to n
>     load "form" & cstr(i)
> next i

> This code blows up on the load due to type mismatch. Is there anyway to
> effect the result of loading Form1 to FormN based on the setting of N?

> Any help would be greatly appreciated.

> Cheers,
> Palmer King



Sun, 30 Dec 2001 03:00:00 GMT  
 VB 6.0 Dynamic Form loading?
Look at the CallByName statement.
I like to give each form a Public Sub Display
with some commands and Show inside it.
You can then try CallByName ("frm" & strName & ".Display")

Jason


Quote:
> Put your forms in array

> frmMyForm(0), frmMyForm(1) etc..

> For i = 0 to n
>  load frmMyForm(i)
> Next i

> should work..

> Regards
> Tim


> > Finally, I'm learning enough about VB to have serious questions.

> > Is there anyway to load a form by deriving its name from a string?

> > For example, I have Form1, Form2, Form3, etc. Based on user input, I
need to
> > load one to n forms, the number being the differentiator. The following
> > doesn't work, but it gives the idea of what I'm trying to do:

> > For i = 1 to n
> >     load "form" & cstr(i)
> > next i

> > This code blows up on the load due to type mismatch. Is there anyway to
> > effect the result of loading Form1 to FormN based on the setting of N?

> > Any help would be greatly appreciated.

> > Cheers,
> > Palmer King



Sun, 30 Dec 2001 03:00:00 GMT  
 VB 6.0 Dynamic Form loading?
I would say that you should use "Objects". That is that you should
create and array of form objects, load them and then when the user
enters a form number you can use the form objects "Show" method. I
will assume that you have previously created the forms that your users
will access? If your program has only one form and that form needs to
be created multiple times, then the following would work just fine.
eg:

Dim UserForm(1 to <how many forms are in your project>) as Form1
For i 1 to 4
   Set UserForm(i) =New Form1
Next i

Now when the user selects to load form, say 3, then you would use

   UserForm(<user selection>).Show

and the form would pop onto the work area or desktop.
This same method would work if you have multiple forms created, you
just load as many as you need, you could create as many of the "Form?"
objects as you need for you users.

You could also use:

    UserForm(<user selection>).Load

and then you could set any properties and invoke any methods
associated with this form before you actually display it on their
screen. Then when you are ready you can use:

     UserForm(<user selection>).Show.

You could also just create the form objects on the fly, on an as
needed basis, when the user elects to load a new form. At that time
you could also name the forms anything that you want using the form
property: UserForm(?).Name=etc.

Hope this will help you.

Regards

Chris



Quote:
>Put your forms in array

>frmMyForm(0), frmMyForm(1) etc..

>For i = 0 to n
> load frmMyForm(i)
>Next i

>should work..

>Regards
>Tim


>> Finally, I'm learning enough about VB to have serious questions.

>> Is there anyway to load a form by deriving its name from a string?

>> For example, I have Form1, Form2, Form3, etc. Based on user input, I need to
>> load one to n forms, the number being the differentiator. The following
>> doesn't work, but it gives the idea of what I'm trying to do:

>> For i = 1 to n
>>     load "form" & cstr(i)
>> next i

>> This code blows up on the load due to type mismatch. Is there anyway to
>> effect the result of loading Form1 to FormN based on the setting of N?

>> Any help would be greatly appreciated.

>> Cheers,
>> Palmer King



Thu, 03 Jan 2002 03:00:00 GMT  
 VB 6.0 Dynamic Form loading?
Try a select case

Dim Form as Integer
Select Case (Form)
    Case 1
        frm1.Show
    Case 2
        frm2.Show
End Select

Quote:

> Finally, I'm learning enough about VB to have serious questions.

> Is there anyway to load a form by deriving its name from a string?

> For example, I have Form1, Form2, Form3, etc. Based on user input, I need to
> load one to n forms, the number being the differentiator. The following
> doesn't work, but it gives the idea of what I'm trying to do:

> For i = 1 to n
>     load "form" & cstr(i)
> next i

> This code blows up on the load due to type mismatch. Is there anyway to
> effect the result of loading Form1 to FormN based on the setting of N?

> Any help would be greatly appreciated.

> Cheers,
> Palmer King

--
Sunny



Tue, 08 Jan 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. VB 6.0 Dynamic Form loading?

2. Loading and unloading vb forms(vb 6.0 service pack 5)

3. how to load custom usercontrol dynamic on form

4. Dynamic loading forms using reflection

5. dynamic form loading

6. dynamic form loading

7. dynamic form loading

8. Dynamic Loading forms

9. Dynamic Loading of Forms

10. Looking for dynamic ComboBox-VBX (goes too long in Form.Load)

11. Forms dynamic loading

12. Dynamic Form Loads: CallByName

 

 
Powered by phpBB® Forum Software