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
Printable View
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
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
http://forums.codeguru.com/Thankz, Drew
[email protected]?SUBJECT=I Love Your Stuff
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
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
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
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
Thanks John:
Ive got it pretty well under control now.
Have tried all the values from 1 to 5
73 RSH
Sounds reasonable, at least from the readability standpoint. Good suggestion.
73 RSH