简体   繁体   English

如何在循环中使vbscript循环进入代码开头

[英]How to make a vbscript loop in loop go to start of code

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? 如何使其再次询问密码? (ps I'm a newbie at coding so please explain yourself. Thanks!) WARNING! (ps我是编码的新手,所以请自己解释一下。谢谢!) 警告! As I said before, if you get the password wrong, it endlessly loops the wrong password message. 正如我之前说过的,如果密码输入错误,它将无休止地循环发送错误的密码消息。

Here's the script you're looking for, I'd suggest just getting rid of the msgbox entirely and appending onto InputBox text. 这是您要查找的脚本,我建议您完全摆脱msgbox并将其附加到InputBox文本上。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM