Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I show a message box with two buttons?

Tags:

vbscript

How can I show a message box with two buttons (For example: "on", "off")?

like image 377
yael Avatar asked Jun 17 '10 14:06

yael


People also ask

What is message box control?

It is a modal window, blocking other actions in the application until the user closes it. A MessageBox can contain text, buttons, and symbols that inform and instruct the user.

How do you use message box?

MessageBox is used to provide confirmations of a task being done or to provide warnings before a task is done. Create a Windows Forms app in Visual Studio and add a button on it. Something like this below. Let's say, you want to show a message on a button click event handler.


3 Answers

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
like image 138
Sam Johnson Avatar answered Oct 27 '22 16:10

Sam Johnson


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]
like image 28
JohnFx Avatar answered Oct 27 '22 17:10

JohnFx


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.

like image 24
jave Avatar answered Oct 27 '22 17:10

jave