How can I show a message box with two buttons?
You probably want to do something like this:
result = MsgBox ("Yes or No?", vbYesNo, "Yes No Example")
Select Case result
Case vbYes
MsgBox("You chose Yes")
Case vbNo
MsgBox("You chose No")
End Select
To add an icon:
result = MsgBox ("Yes or No?", vbYesNo + vbQuestion, "Yes No Example")
Other icon options:
vbCritical or vbExclamation
The VBScript Messagebox is fairly limited as to the labels you can apply to the buttons, your choices are pretty much limited to:
- OK
- Cancel
- Retry
- Abort
- Ignore
- Yes
- No
So you are going to have to build your own form if you want "ON"/"OFF"
Better yet, why not rephrase the prompt in the box so one of the above options works.
For example:
Do you want the light on?
[Yes] [No]
And for God's sake don't do one of these UI monstrosities!
Switch setting? (Click "yes" for ON and "No" for Off)
[Yes] [No]
Remember - if you set the buttons to vbOkOnly
- it will always return 1.
So you can't decide if a user clicked on the close or the OK button. You just have to add a vbOk
option.