Results 1 to 11 of 11

Thread: Sub Main()

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182

    Sub Main()

    Public Sub Main()
    Dim frm As New frmMDI
    frm.Show()
    End Sub
    I used the above code in module.

    In VB it opens the MDI and stays.
    In .Net it doesn't open and stay. Application terminates immediately after doing some process.

    Pls help.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yes Show doesn't hold the thread open you can either use ShowDialog or Application.Run(New frmMDI).

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182
    Thanks. It worked.

    How do I restrict a form to be opened multiple times.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    'Restrict it to open multiple times', What do you mean?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182
    Dim frm As New Form1
    frm.MdiParent = Me
    frm.Show()

    If I use the above, it opens the form every time I call. But I want it to check whether the form is already open.

    I don't want multiple instances of same Form.

  6. #6
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Do you mean restrict a form to only one instance?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182
    Yes

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Single instance of your app or just that form?

    If you mean form then this should get you started: http://www.vbforums.com/showthread.p...hreadid=126418

  9. #9
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Then you could do something like create the for variable a global (dim myFrm as Form1) and then before you create it when needed, you can check to see if myFrm = Nothing. If it is then go ahead and create the one instance. If <> Nothing then either close it and re-open it, do nothing, or set focus to the instance already in existence.

    VB Code:
    1. Dim myFrm As Form1 'Make this a class variable
    2.  
    3. If myFrm Is Nothing Then
    4.      'No instance of the form yet
    5.      myFrm = New Form1
    6.      myFrm.Show() 'or show dialog
    7. Else
    8.      'Instance already exists so take appropriate action here
    9. End If

  10. #10
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Oh, MDI - the link posted by Edneeis will be of more use then

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182
    Cool. It works.

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