2

When running this code;

varCheck=True
Do While varCheck
    Pass=InputBox("Enter Password")
    Do
        If IsEmpty(pass) Then
            WScript.quit
            Exit Do
        End If
        If Pass = "123" Then
            varCheck=False
            Exit Do
        Else
            varCheck=True
            MsgBox("Wrong Password...Try Again")
        End If
    Loop
Loop

If the password is wrong then it doesn't restart to the top of the code, it just endlessly loops the "Wrong Password...Try Again" message box. How do I make it ask the password again? (p.s. I'm a newbie at coding so please explain yourself. Thanks!) WARNING! As I said before, if you get the password wrong, it endlessly loops the wrong password message.

Rich
  • 4,134
  • 3
  • 26
  • 45
Curious George
  • 71
  • 1
  • 1
  • 9

1 Answers1

4

Here's the script you're looking for, I'd suggest just getting rid of the msgbox entirely and appending onto InputBox text. Looks like you forgot to break your inner loop after the wrong password was entered. So it could never get back to the beginning.

varCheck=True
Dim StarterText: StarterText = "" 
Do While varCheck
    Pass=InputBox(StarterText & "Enter Password")
    Do
        If IsEmpty(pass) Then
            WScript.quit
            Exit Do
        End If
        If Pass = "123" Then
            varCheck=False
            Exit Do
        Else
            varCheck=True
            StarterText = "Sorry, wrong password, try again: "

            Exit Do '<-----this is what you forgot. 

        End If
    Loop
Loop
Rich
  • 4,134
  • 3
  • 26
  • 45
  • A few novice questions; how is startertext better/different than msgbox? Also please explain what Dim means and what it is used for/helps with? – Curious George Feb 09 '17 at 17:57
  • startertext is different in that, you see the "wrong password" message in the input box rather than a separate popup. Startertext and message box being better is not the case, because it is a matter of personal preference. Either works fine. `Dim` just allocates variable space and memory for a specific variable. For a good breakdown on `Dim`, look here -> http://www.vbsedit.com/html/87113e7d-b3d4-41c7-85c3-4b9925586707.asp – Rich Feb 09 '17 at 18:04
  • Not a function, it's a variable, like yours named varCheck. – Rich Feb 09 '17 at 22:13
  • 1
    That's what Dim defines. StarterText was just what I named it, I could've named it CornDog and it would've done the same thing. – Rich Feb 09 '17 at 22:16