Help me fix my Closing/QueryUnload routine...

Tabe
08-31-2003, 06:18 PM
I have the following code in an "Exit" menu event and the form_queryunload event. The problem that arises is that the program forces me to answer "Yes" twice to actually exit the program instead of once, whether I select the "Exit" menu option or use the "X" button to close my game.

Note: I wasn't sure on what the parameters for Form_QueryUnload actually do, so had to guess on those values :)


Private Sub mnuGameExit_Click()
Call Form_QueryUnload(0, 0)
End Sub



Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim i As Integer
i = MsgBox("Are you sure you want to exit?", vbYesNoCancel, "Exit Game?")
If i = vbYes Then
UpdateSettings
Unload Me
End
Else:
Cancel = 1
End If
End Sub


Any help would be greatly appreciated!

Thanks,

Tabe
www.tabe.nu

lebb
08-31-2003, 06:27 PM
I'm not sure why you're calling QueryUnload, since it gets called when the form unloads anyway, resulting in being called twice when the user exits from the menu option.

To find the details on the arguments of QueryUnload, have a look in MSDN. This will probably clarify the issue for you.

Deadalus
08-31-2003, 06:29 PM
You don't need to unload it again (with the Unload Me line), if unloading can proceed, simply do nothing.

I didn't see Laura's reply, but now you have the two main problems. Also, don't use End.

Tabe
08-31-2003, 09:33 PM
I thought it had something to do with the Unload Me that I was calling in the QueryUnload :) Anyway, here is the code I'm now using that appears to work correctly:


Private Sub mnuGameExit_Click()
Unload Me 'Call the form's unload routine to verify
'player wants to exit
End Sub



Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim i As Integer
i = MsgBox("Are you sure you want to exit?", vbYesNoCancel, "Exit Game?")
If i = vbYes Then
UpdateSettings 'Save game settings before quitting
Else:
Cancel = 1 'Player didn't want to quit, so cancel the unload
End If
End Sub


Thanks for the help guys.

Tabe
www.tabe.nu

p.s. The MSDN info on Form_QueryUnload's parameters was most unhelpful. It explained the Cancel parameter, which I already had figured out. But it also said UnloadMode's parameter is always 0. What's the point of a parameter if it's value never changes?

alp0001
08-31-2003, 09:37 PM
Look here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbevtQueryUnload.asp) .

Basically, what gets sent to that parameter is based on how the app was closed.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum