18.01.2013 Views

VBScript Reference Manual for InduSoft Web Studio

VBScript Reference Manual for InduSoft Web Studio

VBScript Reference Manual for InduSoft Web Studio

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>VBScript</strong> <strong>Reference</strong> <strong>Manual</strong> <strong>InduSoft</strong> <strong>Web</strong> <strong>Studio</strong><br />

On Error<br />

Description Enables or disables error handling.<br />

Usage On Error Resume Next<br />

On Error GoTo 0<br />

Arguments none<br />

Remarks If you don't use an On Error Resume Next statement anywhere in your code, any run-time error<br />

that occurs can cause an error message to be displayed and code execution stopped. However,<br />

the host running the code determines the exact behavior. The host can sometimes opt to handle<br />

such errors differently. In some cases, the script debugger may be invoked at the point of the<br />

error. In still other cases, there may be no apparent indication that any error occurred because<br />

the host does not to notify the user. Again, this is purely a function of how the host handles any<br />

errors that occur.<br />

Within any particular procedure, an error is not necessarily fatal as long as error-handling is<br />

enabled somewhere along the call stack. If local error-handling is not enabled in a procedure and<br />

an error occurs, control is passed back through the call stack until a procedure with error-handling<br />

enabled is found and the error is handled at that point. If no procedure in the call stack is found to<br />

have error-handling enabled, an error message is displayed at that point and execution stops or<br />

the host handles the error as appropriate.<br />

On Error Resume Next causes execution to continue with the statement immediately following<br />

the statement that caused the run-time error, or with the statement immediately following the<br />

most recent call out of the procedure containing the On Error Resume Next statement. This<br />

allows execution to continue despite a run-time error. You can then build the error-handling<br />

routine inline within the procedure.<br />

An On Error Resume Next statement becomes inactive when another procedure is called, so<br />

you should execute an On Error Resume Next statement in each called routine if you want inline<br />

error handling within that routine. When a procedure is exited, the error-handling capability<br />

reverts to whatever error-handling was in place be<strong>for</strong>e entering the exited procedure.<br />

Use On Error GoTo 0 to disable error handling if you have previously enabled it using On Error<br />

Resume Next.<br />

See Also Err object, Exit<br />

Example The following example illustrates use of the On Error Resume Next statement.<br />

On Error Resume Next<br />

Err.Raise 6 ' Raise an overflow error.<br />

MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description<br />

Err.Clear ' Clear the error.<br />

Option Explicit<br />

Description Forces explicit declaration of all variables in a script.<br />

Usage Option Explicit<br />

Arguments none<br />

Remarks If used, the Option Explicit statement must appear in a script be<strong>for</strong>e any other statements. A<br />

compile-time error occurs whenever a variable is encountered that has not been previously<br />

declared.<br />

When you use the Option Explicit statement, you must explicitly declare all variables using the<br />

Dim, Private, Public, or ReDim statements. If you attempt to use an undeclared variable name,<br />

an error occurs.<br />

Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid<br />

confusion in code where the scope of the variable is not clear.<br />

Example The following example illustrates use of the Option Explicit statement.<br />

Option Explicit ' Force explicit variable declaration.<br />

Dim MyVar ' Declare variable.<br />

184 <strong>InduSoft</strong>, Ltd.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!