【问题标题】:GoTo "Expected Statement"转到“预期声明”
【发布时间】:2017-04-18 22:33:20
【问题描述】:

我正在尝试使用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?")
    If Y = 2 Then
        WScript.Quit
    Else
        If Y = 4 Then
            GoTo top
        Else
            If input = 2 Then
                WScript.Quit

【问题讨论】:

  • 您不能在vbscript 中使用标签。这就是您收到错误的原因。你到底想用这段代码实现什么?
  • @Lankymart:这个问题专门针对On Error Goto。我认为这是一个关于 Goto 本身的不同问题,尽管它当然有相同的答案(Goto 在 VBScript 中不存在)。
  • @PeterCooperJr。确切地说,答案是一样的。如果问题更笼统,它将适合这两种变体。不过,没有任何借口可以提出重复问题。

标签: vbscript compiler-errors


【解决方案1】:

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 <> ""

【讨论】:

  • 同样的错误,在Until input &lt;&gt; "" 行。如有必要,我可以包含整个代码。
  • 我的错。在Until 之前缺少Loop。固定。
  • 错误:没有“做”的“循环”
  • 代码:800A040E.
  • 你写的是Else If而不是ElseIf
【解决方案2】:

试试这个

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

【讨论】:

  • 好的,我会在下一个程序中尝试!
【解决方案3】:

Vbscript 是一种结构化编程语言,结构化编程的主要目标之一是消除 goto 语句,因为它是 considered harmful。 Vbscript 确实有一个用于异常的goto,但这些仅用于在程序退出之前进行资源清理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-09
    • 2018-06-12
    • 2022-11-14
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    相关资源
    最近更新 更多