VB GoTo失败的编译 [英] VB GoTo failing compilation

查看:142
本文介绍了VB GoTo失败的编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下脚本将失败并显示错误,我可以确定。现在,我试图找出我的 On Error GoTo< label> 语法,并且目前正在失败,出现以下错误。

The below script will fail with an error, which I'm ok with. Right now, I'm trying to work out my On Error GoTo <label> syntax, and it is currently failing with the following error.

Line: 2
Char: 16
Error: Syntax Error
Code: 800A03EA
Source: Microsoft VBScript compilation error

代码如下:

Sub ComCheck
    On Error GoTo ErrorHandler

    Dim fortis

    Wscript.Echo("Creating COM object.")
    Set fortis = CreateObject("TESTCOM.APPLICATION")

    Wscript.Echo("Write Database name.")
    Wscript.Echo(fortis.Databases[0].Name)

    GoTo ScriptEnd

ErrorHandler:
    Wscript.Echo("-------ERROR OCCURRED------")
    Wscript.Echo("#" + Err.Number + "::" + Err.Description)
    Err.Clear

ScriptEnd:
    Wscript.Echo("Script complete.")

End Sub

ComCheck()


推荐答案

这是VB和VBScript之间的区别之一:后者不支持 GoTo< label> 语法。 VBScript中唯一的两种可能性是:

This is one of the differences between VB and VBScript: the latter doesn't support the GoTo <label> syntax. The only two possibilities in VBScript are:

On Error Resume Next

On Error Goto 0

您使用前者关闭VBScript自己的错误处理(可能自己处理错误),后者打开VBScript的错误处理(如果遇到错误,则停止所有执行)。

You use the former to turn off VBScript's own error handling (and presumably handle errors yourself), and the latter to turn on VBScript's error handling (which stops all execution if an error is encountered).

这篇关于VB GoTo失败的编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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