Home > Archive > Visual Basic > May 2004 > How to pass Double() array in as ParamArray?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to pass Double() array in as ParamArray?
|
|
| Levan Jgarkava 2004-05-27, 1:31 pm |
| Hi!
I want to be able to pass variable number of Double() arrays to function.
How can I do it in VB/VBA?
Following example shows what I want to do:
------
Public Sub SomeFunction(p_array() As Double, ParamArray params()) As Boolean
' p_array is an array and I can use it as:
Dim b As Double
b = p_array(6)
Dim other
For Each other In params
' Can I use other as array? for example:
Dim a As Double
a = other(5) ' How I can perform something like this but
workable?
Next
End Sub
------
So, what will it be like to work properly?
I'll be greateful for any help.
Best Regards,
Levan Jgharkava
| |
| Rick Rothstein 2004-05-27, 2:30 pm |
| > I want to be able to pass variable number of Double() arrays to
function.
> How can I do it in VB/VBA?
>
> Following example shows what I want to do:
> ------
> Public Sub SomeFunction(p_array() As Double, ParamArray params()) As
Boolean
> ' p_array is an array and I can use it as:
> Dim b As Double
> b = p_array(6)
>
> Dim other
> For Each other In params
> ' Can I use other as array? for example:
> Dim a As Double
> a = other(5) ' How I can perform something like this
but
> workable?
> Next
> End Sub
> ------
>
> So, what will it be like to work properly?
I'm a little at what you want to do. Are you trying to pass in
several different **arrays** into the ParamArray or are you just trying
to treat the values passed into the function after the p_arrays as if
they were an array? My confusion comes from this part of your code...
> For Each other In params
> ' Can I use other as array? for example:
> Dim a As Double
> a = other(5)
> Next
First off, we are not talking about VB.NET, right? Move the Dim
statement out of the loop (put it at the top of the procedure); VB.NET
treats declarations inside of loops differently, VB6 and earlier
doesn't. Now, if you passed in a list of Double values (not arrays) into
params, then you can address params as the array directly
a = params(5)
you wouldn't need the abstraction of going through an intermediate
variable ('a' in you example). If this is not what you mean, please try
to clarify your question.
Rick - MVP
| |
| Tony Proctor 2004-05-27, 2:31 pm |
| Is this what you had in mind Levan:
Public Sub SomeSub(ParamArray params())
Dim iArray As Integer, iElem As Integer
For iArray = 0 To UBound(params)
Debug.Print "Array " & CStr(iArray) & ":"
For iElem = 0 To UBound(params(iArray))
Debug.Print vbTab & "(" & CStr(iElem) & ") = " &
CStr(params(iArray)(iElem))
Next iElem
Next iArray
End Sub
Private Sub Form_Load()
Dim fArr2(0 To 2) As Double
Dim fArr3(0 To 3) As Double
Dim fArr4(0 To 4) As Double
fArr2(0) = 20: fArr2(1) = 21: fArr2(2) = 22
fArr3(0) = 30: fArr3(1) = 31: fArr3(2) = 32: fArr3(3) = 33
fArr4(0) = 40: fArr4(1) = 41: fArr4(2) = 42: fArr4(3) = 43: fArr4(4) =
44
SomeSub fArr2, fArr3, fArr4
End Sub
Give it a try in a Form.
Tony Proctor
"Levan Jgarkava" <levanikoNoSpam@mailru.com> wrote in message
news:eXkAwqAREHA.3140@TK2MSFTNGP11.phx.gbl...
> Hi!
>
> I want to be able to pass variable number of Double() arrays to function.
> How can I do it in VB/VBA?
>
> Following example shows what I want to do:
> ------
> Public Sub SomeFunction(p_array() As Double, ParamArray params()) As
Boolean
> ' p_array is an array and I can use it as:
> Dim b As Double
> b = p_array(6)
>
> Dim other
> For Each other In params
> ' Can I use other as array? for example:
> Dim a As Double
> a = other(5) ' How I can perform something like this but
> workable?
> Next
> End Sub
> ------
>
> So, what will it be like to work properly?
>
> I'll be greateful for any help.
>
> Best Regards,
> Levan Jgharkava
>
>
| |
| Levan Jgarkava 2004-05-27, 6:30 pm |
| Hi!
> Is this what you had in mind Levan:
> .......
> Give it a try in a Form.
Yes. I mean this but here's one problem: I tried to pass param(x) arrays to
another function with parameter arr() as Double and when I was trying to
build compilator warned that I can't pass array of variant as array of
double(something like this). I suppose, that param(x) is treated as array of
variants.
How can I change type of param from array of "Variant"s to array of
"Double"s?
Thanks.
| |
| Levan Jgarkava 2004-05-27, 6:30 pm |
| Hi!
> I'm a little at what you want to do. Are you trying to pass in
> several different **arrays** into the ParamArray or are you just trying
> to treat the values passed into the function after the p_arrays as if
> they were an array?
Yes, I'm trying to pass several different arrays :)
> My confusion comes from this part of your code...
>
[color=darkred]
> First off, we are not talking about VB.NET, right? Move the Dim
> statement out of the loop (put it at the top of the procedure); VB.NET
> treats declarations inside of loops differently, VB6 and earlier
> doesn't.
I know, but at this moment it's not critical. We are talking not about it.
I'm a C++ programmer in common and it was instinctive :)
> Now, if you passed in a list of Double values (not arrays) into
> params, then you can address params as the array directly
>
> a = params(5)
>
> you wouldn't need the abstraction of going through an intermediate
> variable ('a' in you example). If this is not what you mean, please try
> to clarify your question.
I mean, I want to pass several different arrays to my function and also to
be able to pass these arrays down to another function as a "Double" arrays.
I did it with ParamArray p_array(), but it was treated as arrays of Variants
and compilator has objection about it :)
Best Regards,
Levan Jgarkava
| |
| Larry Serflaten 2004-05-27, 10:30 pm |
|
"Levan Jgarkava" <levanikoNoSpam@mailru.com> wrote
> Yes. I mean this but here's one problem: I tried to pass param(x) arrays to
> another function with parameter arr() as Double and when I was trying to
> build compilator warned that I can't pass array of variant as array of
> double(something like this). I suppose, that param(x) is treated as array of
> variants.
> How can I change type of param from array of "Variant"s to array of
> "Double"s?
You can't change them in place, you'd need to create a new array...
But the problem you mention stems from the fact that like a Collection,
the ParamArray is an array of variants. Each member of the array is
a variant, even if you passed them as arrays.
So, don't use a parameter like arr() As Double, use arr As Variant,
and just treat it like it was an array....
LFS
| |
| Levan Jgarkava 2004-05-28, 8:30 am |
| Hi,
> You can't change them in place, you'd need to create a new array...
>
> But the problem you mention stems from the fact that like a Collection,
> the ParamArray is an array of variants. Each member of the array is
> a variant, even if you passed them as arrays.
>
> So, don't use a parameter like arr() As Double, use arr As Variant,
> and just treat it like it was an array....
Thanks you for help. I think that it's good resolution of my task.
Best Regards,
Levan Jgarkava
|
|
|
|
|