ieg
asked on
How do you pass a VBscript array into c# Class method call
I have written a c# class that I use in a VbScript running in windows scripting Host to automate an external application.
It works well and passing simple variables like strings as parameters to methods is Ok
I now want to build an array in Vbscript and pass the array as a parameter to the method
'''''''''''''''''''''''''' '''''''''' '''''''''' '''
e.g. VbScript code
dim strArr(2)
strArr(0) = "01001"
strArr(1) = "01002"
dim obj
set obj = CreateObject("mytest.mytes t")
ok = obj.SetMultipleValues("Sto ckCode", strArr)
set obj = nothing
'''''''''''''''''''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' ''''''''''
The c# code is
public bool SetMultipleValues(string strParamName, string[] strValueArr)
{
//some code that loops through array
}
The error I get is that VbScript says "Invalid procedure call or argument ...."
experimentation indicates that it is the array that is the problem.
I suspect that the Vbscript array is not really an array as c# would expect
Can anyone help?
Thanks
Andy
It works well and passing simple variables like strings as parameters to methods is Ok
I now want to build an array in Vbscript and pass the array as a parameter to the method
''''''''''''''''''''''''''
e.g. VbScript code
dim strArr(2)
strArr(0) = "01001"
strArr(1) = "01002"
dim obj
set obj = CreateObject("mytest.mytes
ok = obj.SetMultipleValues("Sto
set obj = nothing
''''''''''''''''''''''''''
The c# code is
public bool SetMultipleValues(string strParamName, string[] strValueArr)
{
//some code that loops through array
}
The error I get is that VbScript says "Invalid procedure call or argument ...."
experimentation indicates that it is the array that is the problem.
I suspect that the Vbscript array is not really an array as c# would expect
Can anyone help?
Thanks
Andy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In your C# code, you can try to take in an object instead string[] then try to cast it to string[]. You might have to play around with the type you need to pass in and cast to.
Cheers,
Aaron
http://geekswithblogs.net/afeng/
Cheers,
Aaron
http://geekswithblogs.net/afeng/
>>public bool SetMultipleValues(string strParamName, object strValueArr)
yes that's what i meant with option 2, but i'm not sure how a cast to string[] would play out, can you cast an object to string[] in one go?
that's why option 1 using a long string that got split on the C# side is an easier option because you can almost be sure it will work as expected :)
yes that's what i meant with option 2, but i'm not sure how a cast to string[] would play out, can you cast an object to string[] in one go?
that's why option 1 using a long string that got split on the C# side is an easier option because you can almost be sure it will work as expected :)
ASKER
Thanks Brian - I am going to go with your option 1 - it works well.
Andy
Andy
ASKER
using TypeName in Vbscript shows me that I have a variant array.
I don't seem to be able to get this into the c# code because I get a Windows scripting Host error
"Variable uses an Automation type not supported in Vbscript"
Am I right in assuming that Vbscript can't pass the array?
In the c# code i have used system.object to try and capture the variant (see below) but I think this is looking more like a restriction in Vbscript than a c# issue.
public bool SetMultipleValues(string strParamName, object strValueArr)
Any thoughts?
Andy