Article ID: 184740
Article Last Modified on 7/15/2004
184739 : INFO: Where to Obtain the Script Control
Result = ScriptControl.Eval("some text expression")
You can use this method to call both intrinsic script functions, as well as
user functions. Function arguments are passed as literal values in the
expression text and can be either hard-coded or concatenated from a
variable.
Result = ScriptControl.Run("Name", arg1, arg2, ... argn)
You can use this method to call Subroutines, in which case the Result
returned is empty and you can use the alternate calling convention to
ignore the return result:
ScriptControl.Run "Name", arg1, arg2, ... argnNOTE: Name is the name of the Sub or Function, and arg1 ... argn are optional depending on the Sub or Function in question.
ScriptControl.Execute "statement text"This method allows you to call any intrinsic statement or Sub routine. You can also use it to call functions, but the return result is dropped.
Result = ScriptControl.Modules(modulename).functionname(arg1, arg2, ...) ScriptControl.Modules(modulename).subname arg1, arg2, ...
Result = ScriptControl.Modules(GlobalModule).MyFunction(5) ScriptControl.Modules(GlobalModule).MySub 5, "A"
184745 : How To Use Script Control Modules and Procedures Collections
Private Sub Command1_Click()
With ScriptControl1
' Set script language (VBScript is the default).
.Language = "VBScript"
' Set UI interaction (TRUE is the default).
.AllowUI = True
' Copy the script to the control.
.AddCode Text1.Text
' Demonstrate the Eval method.
Debug.Print .Eval("AddTwo(5,7)")
' Demonstrate the Run method both with and without return values.
.Run "Hello", "Jane Doe"
Debug.Print .Run("Hello", "James Smith")
.Run "AddTwo", 4, 6
Debug.Print .Run("AddTwo", 7, 8)
' Demonstrate the ExecuteStatement method.
.ExecuteStatement "Hello ""Sue Smith"""
.ExecuteStatement "AddTwo 9,18"
.ExecuteStatement "MsgBox CStr(AddTwo(3,8))"
.Modules(GlobalModule).Hello "Jane Doe"
Dim oMod As Object
Set oMod = .Modules(GlobalModule)
Debug.Print oMod.AddTwo 12, 24
Set oMod = Nothing
End With
End Sub
Sub Hello(YourName)
MsgBox "Hello " & YourName
End Sub
Function AddTwo(X1, X2)
AddTwo = X1 + X2
End Function
.Run "AddTwo", 4, 6
.ExecuteStatement "AddTwo 9,18"
184739 : INFO: Where to Obtain the Script Control
Additional query words: kbVBA500 kbVBp500 kbNoKeyWord kbVBp600 kbScript kbCtrl
Keywords: kbhowto KB184740