Results 1 to 7 of 7

Thread: Msg Box question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    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.

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    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:
    1. Dim Answer As VbMsgBoxResult
    2. Answer = MsgBox("Save current game?", vbYesNo, "Save", 0, 0)
    3. If Answer = vbYes Then
    4.     frmSave.Show
    5. ElseIf Answer = vbNo Then
    6.     End
    7. End If

    or do this:

    VB Code:
    1. If MsgBox ("Save current game?", vbYesNo, "Save", 0, 0) = vbYes Then
    2.     frmSave.Show
    3. Else
    4.     End
    5. End If

    I'd go with the first.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    Thanks, that worked!

  4. #4

  5. #5
    Lively Member
    Join Date
    Aug 2002
    Location
    SwitzerLANd
    Posts
    65
    little tip:
    i never add the , 0, 0 @ the end, its shorter to write
    just

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



    cYa

  6. #6
    New Member
    Join Date
    Aug 2002
    Posts
    3

    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

  7. #7
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    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
  •  



Click Here to Expand Forum to Full Width