Results 1 to 9 of 9

Thread: loading forms using a string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    London
    Posts
    99

    Cool

    Its a long story but what I need is to be able to load forms by using a string.
    ie

    Load strFormName

    Anybody got any ideas?

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    That's not possible with VB. The best you can do (if you know the names of the forms) is to set up a case statment like

    Select Case strFormName
    Case "MyForm1"
    Load MyForm1
    Case "MyOtherForm"
    Load MyOtherForm
    Case Else
    MsgBox "Unknown form name"
    End Select

  3. #3
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Uh Uh Uh.

    I have had this problem before. Instead of having the name of the form as a string, store a reference to the form.

    e.g.
    Code:
    Dim myForm As Form
    
    'set the form reference
    Set myForm = Form2
    
    Load myForm
    'or
    myForm.Show
    Iain, thats with an i by the way!

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    London
    Posts
    99

    restate problem

    Problem is I've inherited an app' that has 10 forms, with 10 buttons on each form that load one of the ten forms. What has happened is that there was 10 lots of

    button1_click 'etc
    anotherform.show

    on each form. Absolute hell!

    I want to write it as

    cmdbuttons_click(index as integer)
    dim myobj as myformhandler
    dim strname as string
    strname=myobj.formname(index)
    load strname

    Anymore ideas??


  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Does the third button (for example) on each for load the same form? If so then in your new cmdbuttons_click event you can do something like

    Select Case Index
    Case 0
    Load MyForm1
    Case 1
    Load MyForm2
    Case 2
    Load MyOtherForm
    End Select

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    London
    Posts
    99

    Smile

    Yes, it does.

    The problem with doing it like that is that I'll have a big case statement that will be the same across 10 forms.

    I've got all the form names in a DLL in an enum so if I remove or add any forms I only have to do it once. This is what I'm trying to get working.

    There just has to be a way!!!!!!

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Does you app have a code module? If not then create one and a routine in that module that you call using the Index of the button clicked. The routine might look something like

    Public Sub LoadForm(intButton as Integer)

    Select Case intButton
    Case 0
    Load MyForm1
    Case 1
    Load MyForm2
    Case 2
    Load MyOtherForm
    End Select

    End Sub

    And you would call the routine from the Click event of the buttons as follows

    LoadForm Index


  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    London
    Posts
    99

    Smile

    Doh!

    Cheers Martin.


  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    For each n in forms
     if n.name=string then show n
    next n
    Ok i know this wont work but, Is there another property than forms that contains all forms that are not loaded?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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