Results 1 to 18 of 18

Thread: MsgBox results?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    242

    MsgBox results?

    how do i find out what button was pressed on a message box? here is the code i have:
    VB Code:
    1. MsgBox "This scene has been changed. Do you want to save changes?", vbYesNo, "Save Changes"
    but how do i get what button (either the yes or the no button) was pressed?
    Lpeek

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Like:
    VB Code:
    1. If MsgBox("This scene has been changed. Do you want to save changes?", vbYesNo, "Save Changes") = vbYes Then
    2.     'Yes was presssed
    3. End If




    Bruce.

  3. #3
    Lively Member
    Join Date
    Nov 2000
    Location
    NC
    Posts
    66
    Code:
    iAnswer = MsgBox("Do you want to continue?", vbYesNo, "Continue")
    
    If iAnswer = vbYes then
        Continue
    End if

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    And another :

    VB Code:
    1. Select Case MSGBOX("Continue?",VbQuestion+VBYesNo)
    2.  
    3. Case vbYes
    4.  
    5. Case vbNo
    6.  
    7. End Select
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  5. #5
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    I use this way:

    VB Code:
    1. Dim Response As Integer
    2. Response = MsgBox "This scene has been changed. Do you want to save changes?", vbYesNo, "Save Changes"
    3. if Response = vbYes then
    4. 'Code here
    5. else if Response = vbNo then
    6. 'Code here
    7. end if

  6. #6
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586
    ahh heck lets combinine a couple ways into the way I do it

    VB Code:
    1. iAnswer = Msgbox("Whatever", vbYesNo, "Whatever")
    2.  
    3. Select case iAnswer
    4.      Case vbYes
    5.          'Yes Code
    6.      Case vbNo
    7.           'No Code
    8. end select

    The reason for this is you may need to know your answer again later in some coding situations .. never know hehe..

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    VB Code:
    1. Dim Response As VbMsgBoxResult
    2.     Response = MsgBox("hi :D", vbYesNo)

    Technically, and seeing as we're flogging the dead horse out of a problem that could've been answered by one person or even a simple search (!), i thought i'd post it

  8. #8
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748
    how do i find out what button was pressed on a message box? here is the code i have:
    each msgbox arguments has return values. vb assigns these values to the buttons in your message box.
    Code:
    If(msgbox("Are you sure you want to Quit?"?, vbYesNO)=vbYes) then
         msgbox("You Clicked YES")
    else
         msgbox("You Clicked NO")
    end if
    MsgBox Return Values:
    vbOK=1, vbCancel = 2,vbAbort=3, vbRetry =4,vbIgnore = 5, vbYes = 6, vbNo =7
    Last edited by Simply Me; Nov 12th, 2003 at 03:29 AM.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  9. #9
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    Originally posted by da_silvy
    VB Code:
    1. Dim Response As VbMsgBoxResult
    2.     Response = MsgBox("hi :D", vbYesNo)
    how do i get the icon in the message box???



  10. #10
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    You cant
    I would always use the same method as JamesStanich:
    VB Code:
    1. Select Case MsgBox("Save changes?", vbQuestion + vbYesNoCancel, "My App")
    2.    Case vbYes
    3.  
    4.    Case vbNo
    5.    
    6.    Case vbCancel
    7.  
    8. End Select
    No need for any 3rd party varibles and the code is easily changed to handle more or less return values.
    However, if if were just for a yes or no answer then I would use:
    VB Code:
    1. If MsgBox("Save changes?", vbQuestion + vbYesNo, "My App") = vbYes Then
    2.  
    3. Else
    4.  
    5. End If
    Woka

  11. #11
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    I seriously cannot believe that there are 9 (10 now) replies to this thread!

    what a joke

  12. #12

  13. #13
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    Originally posted by Wokawidget
    How do I change the text of a label?

    Woka
    label.text = "changed"

  14. #14
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    another way
    VB Code:
    1. If Not MsgBox("yes or no?!?", vbYesNo) = vbYes Then
    2.         'NO
    3.     Else
    4.         'YES
    5.     End If

  15. #15
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Originally posted by spoiledkid
    label.text = "changed"
    Vb gives me an error:

    "Method or data member not found"

    I am really stuck. This project has to be finished by the end of the day...*sob*

    Or another MsgBox method:
    VB Code:
    1. If Not (Not MsgBox("yes or no?!?", vbYesNo) = vbYes) Then
    2.         'YES
    3.     Else
    4.         'NO
    5.     End If


    Woka

  16. #16
    Lively Member
    Join Date
    Nov 2000
    Location
    NC
    Posts
    66
    lable.caption = "changed"

  17. #17
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    Originally posted by KMcKenzie
    lable.caption = "changed"


    Boy, we really can drag the length of this thread to as long as we like ....

  18. #18
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Hahahahaha...It does't work for me...still get the same error

    Anyways, this will get moved to chit-chat if we ain't careful and to be fair I think everything about returning the response from a MsgBox has been covered so I am gonna go and find another thread to violate in a rather rude way...badger styleeeeee

    Adios,

    Woka

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