Executing a Statement

The ExecuteStatement method is similar to the Eval method, except that a complete Visual Basic statement is allowed. Multiple statements are permitted, provided that they are separated by colons (:) and placed on a single line (although you can use the space/underscore technique to split the text across several physical lines). Figures 13.6 and 13.7 show how to use the ExecuteStatement statement to perform functions that require more than one statement.

Figure 13.6: Assigning values to a module-level variable

Figure 13.7: Displaying a value from a module-level variable

Are you beginning to see a pattern here? After setting the On Error statement, I simply use the ExecuteStatement method of the ScriptControl to execute the statement in the Text1 text box. Listing 13.3 shows the routine that runs when the user clicks the ExecStmt button.

Listing 13.3: Command4_Click Event in MSScript Demo

Private Sub Command4_Click()
On Error Resume Next
ScriptControl1.ExecuteStatement Text1.Text
End Sub

© 1998 SYBEX Inc. All rights reserved.