passing arrays to Sub procedures? 
Author Message
 passing arrays to Sub procedures?

I have been trying to puzzle this one out, but since it is probably such an
easy solution, I am posting it here:
I am trying to pass a number of different array types to sub procedures
(ByRef).
    1) dynamic array
    2) static array
    3) dynamic control array (commandbuttons)
(i assume the syntax is the same for all, but I am specifying just for
clarity.)

'If i have previously declared

    dim MyArray() as string

'and then call

    Private sub AddData(MyArray as string)
        'blah
    End sub

    AddData MyArray

i get a user-defined type error (i don't remember the exact wording) at
run-time, at the line where i call the sub

I have tried also:

    AddData MyArray()

and

    private sub AddData(MyArray() as string)

and

    dim MyArray(0) as string
    private sub AddData(MyArray(0) as string) ' and then using "load
MyArray(1)..." inside procedure to ReDim

How can I make this work?

Thanks,
Joshua Brandt




Fri, 13 Sep 2002 03:00:00 GMT  
 passing arrays to Sub procedures?
Add three buttons in control array to a new form and try these:

Option Explicit
Dim StatArray(0 To 2) As String
Dim DynArray() As String

Private Sub Form_Load()
    ReDim DynArray(0 To 2) As String
    Show

    TestStatic StatArray
    Print StatArray(2)

    TestDynamic DynArray
    Print DynArray(2)

    TestControl Command1
End Sub

Private Sub TestStatic(User() As String)
    User(2) = "See me."
End Sub

Private Sub TestDynamic(User() As String)
    User(2) = "Feel me."
End Sub

Private Sub TestControl(User As Object)
    User(2).Caption = "Touch me."
End Sub

LFS

Quote:

> I have been trying to puzzle this one out, but since it is probably such an
> easy solution, I am posting it here:
> I am trying to pass a number of different array types to sub procedures
> (ByRef).
>     1) dynamic array
>     2) static array
>     3) dynamic control array (commandbuttons)
> (i assume the syntax is the same for all, but I am specifying just for
> clarity.)

> 'If i have previously declared

>     dim MyArray() as string

> 'and then call

>     Private sub AddData(MyArray as string)
>         'blah
>     End sub

>     AddData MyArray

> i get a user-defined type error (i don't remember the exact wording) at
> run-time, at the line where i call the sub

> I have tried also:

>     AddData MyArray()

> and

>     private sub AddData(MyArray() as string)

> and

>     dim MyArray(0) as string
>     private sub AddData(MyArray(0) as string) ' and then using "load
> MyArray(1)..." inside procedure to ReDim

> How can I make this work?

> Thanks,
> Joshua Brandt





Fri, 13 Sep 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing Control Arrays to Sub-Procedures

2. Passing an array to a Sub procedure

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

4. Pass parameter to Sub Main() procedure

5. Pass parameter to Sub Main() procedure

6. Passing Matrics to Sub Procedure

7. Newbie - Passing a string to a sub procedure

8. VB6: Passing datagrid to a sub procedure

9. Having trouble passing object to a sub procedure

10. Passing Parameters into a sub report's stored procedure

11. VB6: Passing datagrid to a sub procedure

12. Getting Variable Array into Sub Procedure

 

 
Powered by phpBB® Forum Software