VBScript / JScript: out Parameter
-
Hi, i should use a Component in VBScript or JScript that has a Function with an out parameter. in VB I can use the Component like this:
Dim myComponent As Component Set myComponent = New Component Dim res As Long Call myComponent.MyFunction(res, "some String", 1, 2, "another Text") If res <> 0 Then MsgBox ("Error while executing MyFunction")
how can I write the VBScript of JScript code that the res variable is passed by reference and not by value, so i can check the value afterwards? Greets Roland -
Hi, i should use a Component in VBScript or JScript that has a Function with an out parameter. in VB I can use the Component like this:
Dim myComponent As Component Set myComponent = New Component Dim res As Long Call myComponent.MyFunction(res, "some String", 1, 2, "another Text") If res <> 0 Then MsgBox ("Error while executing MyFunction")
how can I write the VBScript of JScript code that the res variable is passed by reference and not by value, so i can check the value afterwards? Greets RolandLast I checked, VBScript doesn't support passing by reference. You can only pass by value. EDIT: My bad! Script 5.6 supports passing by reference. Checking into the problem though... RageInTheMachine9532
-
Hi, i should use a Component in VBScript or JScript that has a Function with an out parameter. in VB I can use the Component like this:
Dim myComponent As Component Set myComponent = New Component Dim res As Long Call myComponent.MyFunction(res, "some String", 1, 2, "another Text") If res <> 0 Then MsgBox ("Error while executing MyFunction")
how can I write the VBScript of JScript code that the res variable is passed by reference and not by value, so i can check the value afterwards? Greets RolandOK. When you write your component, all that you need to do is add ByRef to the declaration where 'res' is going to get passed in:
Public Sub MyFunction(ByRef var1 As Integer, var2 As String, var3 As Integer)
I verified that this does work between a VB6 ActiveX control and VBScript on Windows Script 5.6. RageInTheMachine9532
-
OK. When you write your component, all that you need to do is add ByRef to the declaration where 'res' is going to get passed in:
Public Sub MyFunction(ByRef var1 As Integer, var2 As String, var3 As Integer)
I verified that this does work between a VB6 ActiveX control and VBScript on Windows Script 5.6. RageInTheMachine9532
The Problem is: The Component was built with Visual C++ (ATL). The Parameter is declarated as [out] in the type library file, but I sgould be able to tell this the VBScript/JScript. Wit VBScript I get an compile error 'Type mismatch', with JScript it compiles but the Variable is not changed through the Component. I left this problem behind with writing a small C++ App that i call from the Script, but thanks for your help. Of course, if you have some idea, your input is still very welcome. Greets Roland