O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Execute Statement

Syntax

Execute statement
statement

Use: Required

Data Type: String expression

A string expression containing one or more statements for execution.

Description

Executes one or more statements.

Rules at a Glance

  • statement must evaluate to a string that contains one or more executable statements. An executable statement is any call to a user-defined procedure or function, or any intrinsic VBScript command.

  • You can put multiple statements in the expression; separate them with colons.

  • You can also separate the arguments with embedded line breaks.

  • If statement includes an equal sign, it is interpreted as an assignment rather than an evaluation. For example, x = 3 assigns the value 3 to the variable x, rather than comparing the value of the variable x with 3.

  • In VBScript, a program fragment such as x=3 can be interpreted as both an assignment statement (assigning the value 3 to the variable x) or as a comparison expression (for example If x = 3 Then...) The Execute and ExecuteGlobal statements always treat strings of the form a = b as assignment statements. Use Eval to interpret strings of this form as expressions.

Example

The following is a corrected version of an example appearing in online help that appears to do nothing. In this case, the Execute statement is used to execute a procedure named Proc2, and the entire source code for the procedure is also stored to the string S that is passed to the Execute statement:

dim S S = "Proc2 : " S = S & "Sub Proc2 : " S = S & "Dim x : " ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required