bobcory
10-19-2010, 04:17 AM
I have been experimenting with the "Microsoft Script Control" because I need users to be able to write and run scripts from within my application. If you have not used it, here is an example
First you need to get it by:
'Add the "Microsoft Script Control" by Project --> Components --> Microsoft Script Control 1.0
'Also use Project --> References --> Microsoft Script Control 1.0
Or, failing that you can download the .ocx from Microsoft at:
http://www.microsoft.com/downloads/en/details.aspx?FamilyId=D7E31492-2595-49E6-8C02-1426FEC693AC&displaylang=en
Dim strA As String
scrScript.Language = "VBScript"
scrScript.AddObject "MyForm", Me
'Disable a Button
strA = "MyForm.cmdContinue.Enabled = False"
scrScript.ExecuteStatement strA
'Change the Caption
strA = "MyForm.Caption = " & Chr(34) & "It worked!" & Chr(34)
scrScript.ExecuteStatement strA
'Change a Public Variable
strA = "MyForm.strDemo = " & Chr(34) & "This worked too!" & Chr(34) & ": MsgBox MyForm.strDemo"
scrScript.ExecuteStatement strA
'Add some Code (note that lines are separated by colons)
scrScript.AddCode "Function Calc(X): Calc = X * 3: MsgBox Calc: End Function"
scrScript.AddCode "Function Square(X): Square = X ^ 2: MsgBox Square: End Function"
'Run the Code
scrScript.Run "Calc", 7
scrScript.Run "Square", 7
There is a good article here:
http://msdn.microsoft.com/en-us/library/ms974586.aspx
Now to the question: Does anybody know if, or how, this can be extended so that users can add Methods and/or Properties to one of my Classes?
Thanks
Bob
.
First you need to get it by:
'Add the "Microsoft Script Control" by Project --> Components --> Microsoft Script Control 1.0
'Also use Project --> References --> Microsoft Script Control 1.0
Or, failing that you can download the .ocx from Microsoft at:
http://www.microsoft.com/downloads/en/details.aspx?FamilyId=D7E31492-2595-49E6-8C02-1426FEC693AC&displaylang=en
Dim strA As String
scrScript.Language = "VBScript"
scrScript.AddObject "MyForm", Me
'Disable a Button
strA = "MyForm.cmdContinue.Enabled = False"
scrScript.ExecuteStatement strA
'Change the Caption
strA = "MyForm.Caption = " & Chr(34) & "It worked!" & Chr(34)
scrScript.ExecuteStatement strA
'Change a Public Variable
strA = "MyForm.strDemo = " & Chr(34) & "This worked too!" & Chr(34) & ": MsgBox MyForm.strDemo"
scrScript.ExecuteStatement strA
'Add some Code (note that lines are separated by colons)
scrScript.AddCode "Function Calc(X): Calc = X * 3: MsgBox Calc: End Function"
scrScript.AddCode "Function Square(X): Square = X ^ 2: MsgBox Square: End Function"
'Run the Code
scrScript.Run "Calc", 7
scrScript.Run "Square", 7
There is a good article here:
http://msdn.microsoft.com/en-us/library/ms974586.aspx
Now to the question: Does anybody know if, or how, this can be extended so that users can add Methods and/or Properties to one of my Classes?
Thanks
Bob
.