|
-
Apr 1st, 2008, 06:07 AM
#1
Thread Starter
Junior Member
passing ParamArray to another ParamArray
I am using the VBScript control, I have to pass multiple uncertain parameters to the VBScript control.
'my publich business method which is called by many business components:
Public Sub RunTheScript(ByVal s As String, ParamArray items())
'some biz routines here to manipulate items before passing to the script control
ScriptControl.Run(s, items)
End Sub
'the fixed Run method of VBScript control
Private Sub Run(ByVal ProcedureName As String, ParamArray items())
End Sub
'a biz caller
RunTheScript "foo",1,2,3,"a","b","c"
as you can see, I cannot change the behavior of the VBScript control, the items of RunTheScript pass to the ScriptControl.Run, will turn to be an array of array, which is:
items(0)(0) = 1
items(0)(1) = 2
items(0)(2) = 3
items(0)(3) = "a"
items(0)(4) = "b'
items(0)(5) = "c"
that is NOT what I want, I want is the normal result as we all expected:
items(0) = 1
items(1) = 2
items(2) = 3
items(3) = "a"
items(4) = "b'
items(5) = "c"
Anyone could solve the problem?
-
Apr 1st, 2008, 08:09 AM
#2
Re: passing ParamArray to another ParamArray
ParamArray and normal Array are two different things.
With Sub Run(ByVal ProcedureName As String, ParamArray items()), ParamArray items() will be passed as a sequence of parameters of Variant but not an array of parameters.
When call ScriptControl.Run(s, items), you have passed items as one and only one value (a whole array) as the first and single item of ParamArray items() of Sub Run().
Try to change ParamArray in Sub Run() to a normal Array like this:
Code:
Private Sub Run(ByVal ProcedureName As String, items())
'...
End Sub
If that single change does not work then try the code below to convert ParamArray items() to normal Array arItems():
Code:
'my publich business method which is called by many business components:
Public Sub RunTheScript(ByVal s As String, ParamArray items())
'some biz routines here to manipulate items before passing to the script control
Dim i As Integer, arItems()
ReDim arItems(LBound(items) to UBound(items))
For i = LBound(items) to UBound(items)
arItems(i) = items(i)
Next
ScriptControl.Run(s, arItems)
End Sub
'the fixed Run method of VBScript control
Private Sub Run(ByVal ProcedureName As String, items())
'...
End Sub
-
Apr 1st, 2008, 10:26 AM
#3
Re: passing ParamArray to another ParamArray
Since you cannot change the Run procedure but still need to pass each element of the ParamArray as a separate item, figure out what is most likely the maximum number of items in the ParamArray. Add 25 or 50% to that value to allow for future expansion and then use something like the following.
Code:
Public Sub RunTheScript(ByVal s As String, ParamArray items())
Select Case Ubound(items)
Case 0
ScriptControl.Run(s, items(0))
Case 1
ScriptControl.Run(s, items(0), items(1) )
Case 2
ScriptControl.Run(s, items(0), items(1), items(3) )
'...more cases
Case Else
msgbox "Param Array contains too many items."
End Select
End Sub
-
Apr 1st, 2008, 08:25 PM
#4
Thread Starter
Junior Member
Re: passing ParamArray to another ParamArray
hi, that's what I am working around. but I think this is really not a good solution.
-
Apr 2nd, 2008, 12:25 AM
#5
Re: passing ParamArray to another ParamArray
but I think this is really not a good solution.
but it is probably your only option.
-
Apr 2nd, 2008, 07:27 PM
#6
Re: passing ParamArray to another ParamArray
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|