PDA

Click to See Complete Forum and Search --> : Showing Forms dynamically


Aaron Young
Dec 8th, 1999, 12:11 AM
You could create a Collection to which you could add all the Forms, then use there Key to Call them, eg.

Dim MyCollection As New Collection

Private Sub Command1_Click()
'Display a Random Form
MyCollection("Form" & Int((Rnd * 3) + 1)).Show
End Sub

Private Sub Form_Load()
MyCollection.Add Form1, "Form1"
MyCollection.Add Form2, "Form2"
MyCollection.Add Form3, "Form3"
MyCollection.Add Form4, "Form4"
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net


[This message has been edited by Aaron Young (edited 12-08-1999).]

KingStu
Dec 8th, 1999, 02:16 AM
thanks, i was wondering also if there was a way to do something like the following, where the forms could be added to the collection in an iterative way. I can't get it to work whether I use an object type or a string. Something like

Dim strForm as string
For i=1 to 4
StrFormName="Form" & i
MyCollection.Add strForm,strForm
Next i

Aaron Young
Dec 8th, 1999, 06:15 AM
You need to pass the atual Object you wish to Add, passing a String containing the Name of the Form won't work.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

KingStu
Dec 8th, 1999, 11:57 AM
I have an application with forms as follows:
Form1, Form2, Form3, etc
I want to be able to at run time choose which form to display without having to explictly state something like
If x=1 then Form1.show

is there way to say 'form(x).show' for any given "x"? Thanks in advance