PDA

Click to See Complete Forum and Search --> : Msg Box question


Dude1
Aug 9th, 2002, 02:13 PM
I have a problem, I make a Yes/No message box and no matter what I answer the same thing happens:

MsgBox "Save current game?", vbYesNo, "Save", 0, 0

If vbYes Then frmSave.Show
If vbNo Then End

No matter what answer I choose the program ends. What is wrong here?

Thanks.

Rick Bull
Aug 9th, 2002, 02:25 PM
You're not retreiving the return value of the MsgBox. You need to either store it in a variable and then compare it:


Dim Answer As VbMsgBoxResult
Answer = MsgBox("Save current game?", vbYesNo, "Save", 0, 0)
If Answer = vbYes Then
frmSave.Show
ElseIf Answer = vbNo Then
End
End If


or do this:


If MsgBox ("Save current game?", vbYesNo, "Save", 0, 0) = vbYes Then
frmSave.Show
Else
End
End If


I'd go with the first.

Dude1
Aug 9th, 2002, 03:01 PM
Thanks, that worked!

Rick Bull
Aug 9th, 2002, 03:30 PM
Good :D

-=R0ckAw4Y=-
Aug 9th, 2002, 04:11 PM
little tip:
i never add the , 0, 0 @ the end, its shorter to write :cool: :D
just

what:
If MsgBox("What the ****?", vbYesNo + vbExclamation, "****?") = vbYes Then GoTo what

;)

cYa

dinacherry_77
Aug 9th, 2002, 04:34 PM
I have a problem, I make a Yes/No message box and no matter what I answer the same thing happens:

MsgBox "Save current game?", vbYesNo, "Save", 0, 0

If vbYes Then frmSave.Show
If vbNo Then End

No matter what answer I choose the program ends. What is wrong here?

You are basically checking for the VBYes VBNo values, whihc you should not. You should store the result of the value returned by the message box then chekc if it is VBYes then show the form or end the program

The solution would be
dim i as integer
if VBYes=MsgBox("Save current game?", vbYesNo, "Save", 0, 0)Then
frmSave.Show
Else
End
End If

Rick Bull
Aug 10th, 2002, 06:19 AM
Ummm, didn't I already give that advice and solve his problem? :confused: