Return Value From VBScript In .NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Derek Hart

    Return Value From VBScript In .NET

    I am using an MSScriptControl in vb.net to do an evaluation of a text
    string:
    tempAnswer = MyScriptControl .Eval(MyScriptS tring)

    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

    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?




  • =?Utf-8?B?dXJrZWM=?=

    #2
    RE: Return Value From VBScript In .NET

    "Derek Hart" wrote:
    I am using an MSScriptControl in vb.net to do an evaluation of a text
    string:
    tempAnswer = MyScriptControl .Eval(MyScriptS tring)
    >
    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 _
    ("MSScriptContr ol.ScriptContro l")
    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(s trCode)

    Dim objRetVal As Object

    For i = 0 To 20
    objRetVal = objSC.Run("Foo" , i)
    Console.WriteLi ne(objRetVal)
    Next

    Console.ReadLin e()


    --
    urkec

    Comment

    Working...