Results 1 to 9 of 9

Thread: BUG: Q189812 - VB hangs . . .

  1. #1
    Guest
    "In Visual Basic, if one form shows another form modally, and the second form tries to unload the first form in either its Unload or Query_Unload event, Visual Basic hangs."

    On January 5th, Microsoft said they were actively looking for a fix, I'm tired of waiting.

    Does anyone have there own idea?

    If form1 calls form2 (vbmodal) and I want to exit my app from form2 I use this code:

    Dim Frm As Form

    For Each Frm In Forms
    Unload Frm
    Set Frm = Nothing
    Next Frm

    The problem is that when it tries to unload form1 it will immediately try to unload form2 (on its own, not using the above routine) and hang. Any ideas?

    Thanks!!

  2. #2
    Guest
    Yes,
    1. Unload your forms in a diffent order.
    2. Use "End"

    I would not recommend using End as it will 'kill' your program and not unload anything. Like clicking the 'stop' button in the debugger.

    Gerco Dries.

  3. #3

  4. #4
    Guest
    For some reason the QueryUnload is being called twice for certain forms. It doesn't matter if I use

    For nNdx = Forms.Count - 1 To 0 Step -1
    Unload Forms(nNdx)
    Next

    OR THIS

    For Each Frm In Forms
    Unload Frm
    Set Frm = Nothing
    Next Frm

    Even if I 'stop' the app using the IDE my app still hangs on an exit.

  5. #5

  6. #6
    Guest
    'On error resume next' doesn't work either.

    When QueryUnload tries to run the second time, the return value (UnloadMode) has a value of '5'. This value isn't listed in the return values for 'QueryUnload Event', only 0 through 4.

  7. #7
    Guest
    The MSDN library shows a return value of 5 as "A form is closing because its owner is closing."

  8. #8
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754

    Lightbulb

    I'm guessing here, so if i'm wrong please correct me.

    I think maybe your problem lies in the parent-child relationship between the windows in your app.

    By parent-child I mean how win32 platform interprets the windows in the app, not MDI.

    i.e. the first window you load is the parent window, and then the second and third forms you load are child windows of that first window, so when you try to unload a parent from a child it's a cyclic call...
    If this is the case, then maybe you've got to work out how to make all your forms independent windows of each other. If it's not the case then it was my best guess.
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  9. #9
    Guest

    Thumbs up

    Your theory is right cripsin. What I've had to do is unload each form as a new form opens. If I need to open a previously opened form I reload it and put the saved values back into the form when it opens. It's not the way I wanted to do things, but it's working.

    Thanks for everyone's help.

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