The Run method differs from the Eval and ExecuteStatement methods in that the code must be added using the AddCode method before you can use the Run method. The code you add must be a complete subroutine or function, and it can even accept parameters. Figure 13.8 illustrates adding a subroutine, and Figure 13.9 shows the results of running that subroutine.
Figure 13.8: Adding a subroutine
Figure 13.9: Running the subroutine
Listing 13.4 shows how to run your subroutine. This time, rather than passing the actual code itself to the Run method, I merely pass the name of the subroutine I want to run.
Listing 13.4: Command1_Click Event in MSScript Demo
Private Sub Command1_Click()
On Error Resume Next
ScriptControl1.Run Text2.Text
End Sub