Results 1 to 4 of 4

Thread: Showing Forms dynamically

  1. #1

    Thread Starter
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    You could create a Collection to which you could add all the Forms, then use there Key to Call them, eg.
    Code:
    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
    [email protected]
    [email protected]


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

  2. #2
    New Member
    Join Date
    Nov 1999
    Location
    MD,USA
    Posts
    13

    Post

    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

  3. #3

    Thread Starter
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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
    [email protected]
    [email protected]

  4. #4
    New Member
    Join Date
    Nov 1999
    Location
    MD,USA
    Posts
    13

    Post

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width