
passing array to a usercontrol
Quote:
>Does anyone know how to pass an array to a usercontrol? I tried the
>following way, and I had no luck.
>I keep receiving the error "Wrong data type or user define type
>expected"
>Any help will be appreciated.
>Private Sub Command2_Click()
>Dim a As Variant
>a(0) = 0
>a(1) = 2
>a(2) = 2
First of all, a Variant is not an array, though it can HOLD an array.
If it DOES hold an array, then you can apply the indexes directly to
the variable as above. So you need either to declare *a* as an array:
Dim a(0 To 2) As Integer '(or whatever type)
or you need to assign an array to *a*:
a = Array(0, 0, 0)
Now you can assign to a(0), a(1) and a(2).
Quote:
>Call UserControl1.WriteDrive(&H100, 3, a)
>End Sub
>In UserControl1 is the following:
>Public Function WriteDrive(ByRef start_addr As Integer, num_of_addresses
>As Integer, ByRef Values() As Variant) As Boolean
>a = values()
>b = values()
>End Function
You're making *a* a variant, but you're defining WriteDrive to expect
an ARRAY of variants. Try "ByRef Values as Variant". This will also
work if *a* was Dim'ed as an array in the first place, but in that
case there is an additional option for the parameter declaration
inside WriteDrive's argument list. If you had
Dim a(0 to 2) As Integer
you could use
ByRef Values() as Integer