12.17.8    Display errors (Debug a VB Script)

Debug VB Script Example.

This script is used to debug an VB Script and print errors to BWSPOOL message window. You to enter the name of the Script to be tested in a Text-type tag named TestScriptname. Note that ACTION commands do not usually return errors.  The catch commands displays errors by the VB Script KEYWORD commands. Note that a VB script can debug only another VB Script. A VB Script can not debug Tcl Script or JScript.
The JScript version is at 12.14.8 Display errors (Debug a JScript).
The Tcl Script version is at 12.10.8 Display errors (Debug a Tcl Script).

 

Rem DebugVBScript.vbs - a VB Script

Rem to print errors of other VB scripts.

Dim fso, filespec, msg

 Set fso = CreateObject("Scripting.FileSystemObject")

 filespec = GETVAL("TestScriptName")

On Error Resume Next

SCREXEC filespec

WINEXEC "BWSPOOL.EXE"

   If (fso.FileExists(filespec)) Then

      msg = filespec & " exists."

      BWSPOOL msg

      BWSPOOL VbCrLf

      If Err.Number <> 0 Then

        rem print error number and description

        BWSPOOL "Error # " & CStr(Err.Number) & " " & Err.Description

        SETVAL "ERROR=" & CStr(Err.Number) & " " & Err.Description

        rem print carriage return and line feed

        BWSPOOL VbCrLf

      Else

        BWSPOOL "No reported errors "

        BWSPOOL filespec

        BWSPOOL VbCrLf

      End If

   Else

      msg = filespec & " doesn't exist."

      rem print carriage return and line feed

      BWSPOOL msg

       BWSPOOL VbCrLf

   End If

 

Rem OnError statement is found at

Rem   MSDN Home >  MSDN Library >  Web Development >  Scripting >  Windows Script Technologies >  VBScript >  Reference >  Statements

Rem http://msdn.microsoft.com/library/en-us/script56/html/vsstmOnError.asp

 

Rem The Error object "Err" is found at:

Rem MSDN Home >  MSDN Library >  Web Development >  Scripting >  Windows Script Technologies >  VBScript >  Reference >  Objects and Collections

Rem http://msdn.microsoft.com/library/en-us/script56/html/vsobjErr.asp

 

Rem The FileExists method is at

Rem MSDN Home >  MSDN Library >  Web Development >  Scripting >  Windows Script Technologies >  Script Runtime >  FileSystemObject Object >  Reference >  Methods

Rem http://msdn.microsoft.com/library/en-us/script56/html/jsmthFileExists.asp