CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: MsgBox

  1. #1
    Join Date
    Oct 2000
    Location
    Upstate NY
    Posts
    249

    MsgBox

    My Book is rather vague about the various MsgBox functions. Could someone please Pass along the code to generate a MsgBox with a Yes, No, and Cancel Button and the code to retrieve the response. Thanks RSH


  2. #2
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    150

    Re: MsgBox


    private Sub Command1_Click()
    If MsgBox("This is a message box.", vbYesNoCancel, "The Title") = vbYes then
    MsgBox "you clicked yes", vbOKOnly, "Result"
    ElseIf MsgBox("This is a message box.", vbYesNoCancel, "The Title") = vbNo then
    MsgBox "you clicked No", vbOKOnly, "Result"
    End If
    End Sub




    Thankz, Drew
    [email protected]?SUBJECT=I Love Your Stuff
    Thanks, Drew

  3. #3
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: MsgBox

    Heres a similar way


    Dim res%
    res% = MsgBox("This is a message box.", vbYesNoCancel)
    If res% = vbYes Then
    MsgBox "you press yes"
    ElseIf res% = vbNo Then
    MsgBox "you press no"
    Else
    MsgBox "you pressed cancel"
    End If



    David Paulson


  4. #4
    Join Date
    Oct 2000
    Location
    Upstate NY
    Posts
    249

    Re: MsgBox

    Both very good answers.
    In the meantime I found another book and came up with this.

    Dim Reply
    Reply = MsgBox("ARE YOU SHURE YOU WANT TO DELETE THIS FILE", 3, "CAUTION")
    If (Reply = 7) Or (Reply = 2) Then Exit Sub
    If Reply = 6 Then Goto Blah Blah.
    Apperantly the 3 determines the type of box.
    73 RSH


  5. #5
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: MsgBox

    You should use the constant values in stead of the numbers, this will improve readability for yourself, and for anyone who needs to read your code. So instead of using 7,2 or 6, use vbNo, vbCancel and vbYes.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: MsgBox

    GO to the Help facility and search on MSGBOX Function. Select VB reference and it will tell all you ever want to know about the MSGBOX Dialog including what the 3 means (Yes,No,Cancel)

    John G

  7. #7
    Join Date
    Oct 2000
    Location
    Upstate NY
    Posts
    249

    Re: MsgBox

    Thanks John:
    Ive got it pretty well under control now.
    Have tried all the values from 1 to 5
    73 RSH


  8. #8
    Join Date
    Oct 2000
    Location
    Upstate NY
    Posts
    249

    Re: MsgBox

    Sounds reasonable, at least from the readability standpoint. Good suggestion.
    73 RSH


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

Featured