|
-
Aug 9th, 2002, 02:13 PM
#1
Thread Starter
Addicted Member
Msg Box question
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.
-
Aug 9th, 2002, 02:25 PM
#2
Frenzied Member
You're not retreiving the return value of the MsgBox. You need to either store it in a variable and then compare it:
VB Code:
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:
VB Code:
If MsgBox ("Save current game?", vbYesNo, "Save", 0, 0) = vbYes Then
frmSave.Show
Else
End
End If
I'd go with the first.
-
Aug 9th, 2002, 03:01 PM
#3
Thread Starter
Addicted Member
-
Aug 9th, 2002, 03:30 PM
#4
-
Aug 9th, 2002, 04:11 PM
#5
Lively Member
-
Aug 9th, 2002, 04:34 PM
#6
New Member
MsgBox "Save current game?", vbYesNo, "Save", 0, 0
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
-
Aug 10th, 2002, 06:19 AM
#7
Frenzied Member
Ummm, didn't I already give that advice and solve his problem?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|