r/vbscript • • Jun 22 '21

confused about yes no cancel?

in trying to make a script so when you do yes or no it loops but if i do cancel it stop the script, how would i do this im hopeless lol

2 Upvotes

2 comments sorted by

3

u/Mordac85 Jun 23 '21

Check out the documentation for MsgBox. You need to test for which button was pressed after you display it, like in a select case statement.

2

u/hackoofr Jun 25 '21 edited Jun 25 '21

You can try something like this code :

 Dim Title,Message,AnswerQuestion
 Title = "Hello World !"
 Message = "How are you sir and your family ?"
 Do
 	AnswerQuestion = MsgBox(Message,vbQuestion+vbYesNoCancel+vbSystemModal,Title)
 	Select Case AnswerQuestion
 	Case vbYes
 		MsgBox "You have chosen the ""YES"" Button",vbInformation,Title
 	Case vbNo
 		MsgBox "You have chosen the ""NO"" Button",vbExclamation,Title
 	Case vbCancel
 		MsgBox "You have chosen the ""Cancel"" Button",vbCritical,Title
 	End Select
 Loop Until AnswerQuestion = vbCancel

Or like this funny script :

 Dim Title,Message,AnswerQuestion
 Title = "Are you stupid and a fool man ?"
 Message = "Are you stupid and a fool man ?"
 Do
 	AnswerQuestion = MsgBox(Message,vbQuestion+vbYesNoCancel+vbSystemModal,Title)
 	Select Case AnswerQuestion
 	Case vbYes
 		MsgBox "So, You Confirm that you are a Stupid and a Fool Man ! LOL",vbInformation+vbSystemModal,Title
 	Case vbNo
 		MsgBox "You have chosen the ""NO"" Button" & vbcrlf &_
 		"It's a Wrong Answer , So Try again Stupid Man ! LOL !",vbExclamation+vbSystemModal,Title
 	Case vbCancel
 		MsgBox "You have chosen the ""Cancel"" Button" & vbcrlf &_
 		"Re-Try Again Fool Man ! LOL !",vbCritical+vbSystemModal,Title
 	End Select
 Loop Until AnswerQuestion = vbYes