如何在循环中使vbscript循环转到代码开头 [英] How to make a vbscript loop in loop go to start of code

查看:118
本文介绍了如何在循环中使vbscript循环转到代码开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行此代码时;

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.

推荐答案

这是您要查找的脚本,我建议您完全摆脱msgbox并将其附加到InputBox文本上.输入密码错误后,您似乎忘记了中断内部循环.因此,它永远都不可能回到开始.

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

这篇关于如何在循环中使vbscript循环转到代码开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆