报告某行代码中包含错误的特定字符。
Object.Character
Character 属性返回一个带符号的长整型数。
有些错误和特定字符位置无关。例如,考虑错误 Expected End If。在这种情况下,没有任何行(缺少代码行)。此时,Character 属性返回零 (0)。
字符位置按照相对于位置 (1)(某行中驻留在位置 1 的第一个字符)的偏移来确定。
下面的代码演示 WshRemoteError 对象如何展示代码行中有错误的字符。
Dim Controller, RemoteScript
Set Controller = WScript.CreateObject("WSHController")
Set RemoteScript = Controller.CreateScript("test.js", "remoteserver")
WScript.ConnectObject RemoteScript, "remote_"
RemoteScript.Execute
Do While RemoteScript.Status <> 2
WScript.Sleep 100
Loop
Sub remote_Error
Dim theError
Set theError = RemoteScript.Error
WScript.Echo "Error - Line: " & theError.Line & ", Char: " & theError.Character
& vbCrLf & "Description: " & theError.Description
WScript.Quit -1
End Sub
var Controller = WScript.CreateObject("WSHController");
var RemoteScript = Controller.CreateScript("test.js", "remoteserver");
WScript.ConnectObject(RemoteScript, "remote_");
RemoteScript.Execute();
while (RemoteScript.Status != 2) {
WScript.Sleep(100);
}
function remote_Error()
{
var theError = RemoteScript.Error;
WScript.Echo("Error - Line: " + theError.Line + ", Char: " + theError.Character
+ "\nDescription: " + theError.Description);
WScript.Quit(-1);
}
WshRemote 对象 | WshRemoteError 对象 | Line 属性| Description 属性 | SourceText 属性 | Number 属性 | Source 属性