【问题标题】:How to make a vbscript loop in loop go to start of code如何使循环中的vbscript循环转到代码的开头
【发布时间】:2017-02-09 15:39:35
【问题描述】:

运行此代码时;

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

如果密码错误,它不会重新启动到代码顶部,它只是无休止地循环“密码错误...再试一次”消息框。如何让它再次询问密码? (附:我是编码新手,所以请解释一下。谢谢!) 警告!正如我之前所说,如果您输入错误的密码,它会无限循环错误的密码信息。

【问题讨论】:

  • 您是否尝试过在您的 msgbox 之后放置 Exit Do

标签: loops vbscript inputbox do-loops


【解决方案1】:

这是您要查找的脚本,我建议您完全摆脱 msgbox 并附加到 InputBox 文本上。输入错误密码后,您似乎忘记了打破内部循环。所以它永远无法回到最初。

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

【讨论】:

  • 几个新手问题; startertext 如何比 msgbox 更好/不同?另请解释 Dim 的含义以及它的用途/帮助?
  • startertext 的不同之处在于,您会在输入框中看到“密码错误”消息,而不是单独的弹出窗口。 Startertext 和 message box 更好不是这样,因为这是个人喜好的问题。要么工作正常。 Dim 只是为特定变量分配变量空间和内存。要详细了解Dim,请看这里 -> vbsedit.com/html/87113e7d-b3d4-41c7-85c3-4b9925586707.asp
  • 不是一个函数,它是一个变量,就像你的 varCheck 一样。
  • 这就是 Dim 的定义。 StarterText 就是我给它取的名字,我可以给它取名为 CornDog,它也会做同样的事情。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多