"Derek Hart" wrote:
I am using an MSScriptControl in vb.net to do an evaluation of a text
string:
tempAnswer = MyScriptControl.Eval(MyScriptString)
But how can I use this to get a return value from a vbscript function:
Function Foo() As Integer
If MyValue = 1 Then
Foo=1
Else
Foo=2
End
End Function
The above is not valid VBScript code. You can not declare function return
type and the If statement needs the closing End if.
tempCode = "Code Above - Read From A Database"
tempAnswer = MyScriptControl.Run(tempCode)
Do I use the Run command. I do not see a return statement in vbscript. Can
this be done in vb.net?
MSScriptControl.Run() has a return value and you can use it to run a
VBScript function and get the return value:
Dim objSC As Object
objSC = CreateObject _
("MSScriptControl.ScriptControl")
objSC.Language = "VBScript"
Dim strCode As String
strCode = "Function Foo(intVal)" & vbCrLf _
& "If intVal = 1 Then " & vbCrLf _
& "Foo = 1 " & vbCrLf _
& "Else" & vbCrLf _
& "Foo = 2" & vbCrLf _
& "End If" & vbCrLf _
& "End Function"
objSC.AddCode(strCode)
Dim objRetVal As Object
For i = 0 To 20
objRetVal = objSC.Run("Foo", i)
Console.WriteLine(objRetVal)
Next
Console.ReadLine()
--
urkec