Today I started trying to create my own custom Dialog boxes for Windows. I'm able to use a shortcut/wscript.exe to run a VBS file with the following: (please ignore the dialog. I know that Drive C: will not be wiped and I do not intend for that to happen. This is just practice before I make useful ones.)

Option Explicit
x=MsgBox("Proceeding will wipe the contents of your C: Drive. Proceed?", 1+48, "Format Drive C:")

My scripting works to this point, as shown below: enter image description here

But when I click OK or Cancel at this point, then I get an error. In the past, clicking OK or Cancel just closed out of this completely, but now I get a run-time error, which I think is better than nothing at all. However, an error doesn't help me.

enter image description here

Option Explicit
x=MsgBox("Proceeding will wipe the contents of your C: Drive. Proceed?", 1+48, "Format Drive C:")
If x=1 Then
y=MsgBox("The contents of your C: Drive could not be successfully deleted.", 0+64, "Error Formatting Drive C: - System Error 5")
If x=2 Then
x=MsgBox("Not all of the contents of your C: Drive were successfully deleted. Please try again.", 0+64, "Error Formatting Drive C: - System Error 303")

If I add "instructions" for what should happen next, then I get an error when I open the file and I can't do anything at all

enter image description here

I have tried changing much of the code already. I have tried using dim, removing x, defining a variable, define subsequent msgboxs as variables, removing the parentheses, etc... I have only started writing my own VBS files today, but I have been doing batch scripting with .bat files for a long time. Even with the change of language, all my troubleshooting has led me nowhere, and I am almost positive that I have defined the variable correctly.

Can anyone tell me if I have done this right? I have tried numerous examples, but even Microsoft's Official Webpage on VBS-MsgBox is useless. I apologize in advance if I have made a stupid mistake somewhere, but I have already changed almost all of the code and I am still stuck.

Any help would be greatly appreciated. I've already spent 4 hours trying to fix this one problem.


Give a try for this example :

Option Explicit
Dim Title,Question
Title = "user input in VBS with MsgBox"
Question = MsgBox("Proceeding will wipe the contents of your C: Drive. Proceed ?",vbYesNo+vbQuestion, Title)
If Question = vbYes Then
    MsgBox "We proceed wipping your C:\ drive",vbExclamation,Title
    'Call your sub here to continue proceeding your script
    MsgBox "Canceling the operation !",vbCritical,Title
End If

For more informations about MsgBox Constants

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.