passing array to a usercontrol 
Author Message
 passing array to a usercontrol

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
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

Thanks in Advance.



Mon, 08 Jan 2001 03:00:00 GMT  
 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



Mon, 08 Jan 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Pass array to UserControl ???

2. Parent UserControl's Properties in a UserControl (placed on another UserControl)

3. Passing Arguments / Passing an Array

4. Passing array from VB to DLL and returning array

5. Passing an array (or array of a structure) from VB to VC++

6. Passing Array to Session Variable Then back to Array

7. How to pass an integer array/userdef type array into an Oracle Stored procedure

8. Problem passing a usercontrol object from VBScript?

9. Passing a global variable between UserControl *.ocx's

10. How to pass a VB intrinsic Control as parameter to an ActiveX control (UserControl)

11. Passing a UserControl to a code module

12. UserControl can not be passed outside the project?

 

 
Powered by phpBB® Forum Software