Vbscript 转到“预期语句”
我正在尝试使用GoTo命令,但我不知道任何替代方法,它可以批量正常工作。无论何时尝试加载程序,都会出现以下错误: 这里的错误基本上是第11行第3列Vbscript 转到“预期语句”,vbscript,compiler-errors,Vbscript,Compiler Errors,我正在尝试使用GoTo命令,但我不知道任何替代方法,它可以批量正常工作。无论何时尝试加载程序,都会出现以下错误: 这里的错误基本上是第11行第3列 top: input = InputBox("Enter normal text:", "Message Encrypt Style 2", "Text goes here") If input = "" Then Y = MsgBox("You inputed nothing!", vbRetryCancel+64, "Huh?")
top:
input = InputBox("Enter normal text:", "Message Encrypt Style 2", "Text goes here")
If input = "" Then
Y = MsgBox("You inputed nothing!", vbRetryCancel+64, "Huh?")
If Y = 2 Then
WScript.Quit
Else
If Y = 4 Then
GoTo top
Else
If input = 2 Then
WScript.Quit
试试这个
Option Explicit
Dim Input ' as string
Dim Y ' as msgbox response
Input = ""
Do Until Input <> ""
Input= InputBox("Enter normal text:", "Message Encrypt Style 2", "Text goes here")
If Input = "" Then
Y = Msgbox ("You input nothing", vbRetryCancel, "Huh?")
If Y = vbCancel Then
WScript.Quit
End If
ElseIf Input = "2" Then
WScript.Quit
End If
Loop
' Proceed here if input is valid
VBScript没有Goto语句,而且还有一种更干净的方法
Do
input = InputBox(...)
If IsEmpty(input) Or input = "2" Then
WScript.Quit
ElseIf input = "" Then
MsgBox "No input."
End If
Loop Until input <> ""
Vbscript是一种结构化编程语言,结构化编程的主要目标之一是消除goto语句。Vbscript确实对异常有一个goto,但这些仅用于程序退出前的资源清理。不能在Vbscript中使用标签。这就是为什么会出现错误。你到底想用这段代码实现什么?可能是@Lankymart的重复:这个问题是关于错误转到的。我认为这是一个关于Goto本身的不同问题,当然它有相同的答案,即Goto在VBScript中不存在。@PeterCooperJr。答案是一样的。如果问题更一般,它将适合这两种变体。没有理由问dup问题。好吧,我会在我的下一个节目中尝试!相同的错误,在直到输入行。如果需要的话,我可以包含整个代码。我的错。在测试之前,有一个循环丢失。已修复。错误:“循环”没有“do”代码:800A040E。您编写了Else If而不是ElseIf。