-2

I was creating a vbs but after i click Yes in msgbox, it instead does what the "No" is supposed to do. Here is my code:

X=MsgBox("Please Restart. Our system will break down.",4+4096, ErR0r)
if vbNo then
 X=MsgBox("e")
 dim count
 set object = wscript.CreateObject("wscript.shell")

 do
 object.run "error.vbs"
 count = count + 1
 loop until count = 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
end if

if vbYes then
   Dim IntCounter
   Dim objWshShl : Set objWshShl = WScript.CreateObject("wscript.shell")
   Dim objVoice : Set objVoice = WScript.CreateObject("sapi.spvoice")

   ShutdownWarning()
   TimedMessageBox()
   ShutdownComputer()

   Function ShutdownWarning
        X=MsgBox("happy late april fools, hehe", 0+4096)
    WScript.Sleep 5000
   End Function

   Function TimedMessageBox
    For IntCounter = 5 To 1 Step -1
    objWshShl.Popup "Your time will be wasted in " _
    & IntCounter & " seconds",1,"Computer Shutdown", 0+4096
    Next
   End Function

   Function ShutdownComputer
    objWshShl.Run "Shutdown /s /f /t 0",0
   End Function
end if

does anyone have solutions to this? (im not trying to create a legitimate virus, this is just a prank i made for fun)

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

1

vbNo is a constant value equal to 7.

if vbNo will always be true, since 7 is not a falsy value.

You need to use a variable to get the return value of the user input, such as :

userInput = msgBox("click yes or no", vbYesNo)
if userInput = vbNo Then
   ' do something
end if
Cid
  • 14,968
  • 4
  • 30
  • 45