ScriptControl控件使用

實例1

Private Sub Command1_Click()
On Error GoTo scError
Dim strFun As String
Dim a, b As Long
x = 2
b = 3
strFun = “function Add(a,b)” & vbCrLf & “Add=a+b+s” & vbCrLf & “End Function” & vbCrLf
ScriptControl1.Modules.Add “MyCode”
ScriptControl1.Modules.Item(1).AddCode strFun
ScriptControl1.ExecuteStatement (“x=10”)
MsgBox ScriptControl1.Run(“Add”, x, b)

打印錯誤代碼

scError:
’ 使用 Error 對象向用戶通告
’ 錯誤,以及出錯行。
Debug.Print ScriptControl1.Error.Number & _
“:” & ScriptControl1.Error.Description & _
" in line " & ScriptControl1.Error.Line
end sub

實例2

Dim sc
Dim strProgram As String
strProgram = “Sub Main” & vbCrLf & _
“MsgBox ““Hello World””” & vbCrLf & _
“End Sub”
Set sc = CreateObject(“ScriptControl”)
sc.Language = “VBScript”
sc.AddCode strProgram
sc.Run “Main”

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章