Click to See Complete Forum and Search --> : MsgBox


RSH
October 8th, 2001, 04:56 PM
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

Moses420ca
October 8th, 2001, 05:28 PM
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://www.geocities.com/moses420ca/images/thumbnails/drewblue2.jpgThankz, Drew
Moses420ca@yahoo.ca?SUBJECT=I Love Your Stuff

d.paulson
October 8th, 2001, 05:52 PM
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

RSH
October 8th, 2001, 07:18 PM
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

Cakkie
October 9th, 2001, 01:24 AM
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
slisse@planetinternet.be

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

John G Duffy
October 9th, 2001, 03:08 PM
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

RSH
October 9th, 2001, 06:42 PM
Thanks John:
Ive got it pretty well under control now.
Have tried all the values from 1 to 5
73 RSH

RSH
October 9th, 2001, 06:46 PM
Sounds reasonable, at least from the readability standpoint. Good suggestion.
73 RSH