Passing Arrays to procedures

  • Thread starter Thread starter Tony Wainwright
  • Start date Start date
T

Tony Wainwright

Hi Guys,

I need some help in passing arrays to procedures. In my main event I have create an array as in:

Dim Harry(1) as String
Call MyProcedure (Harry)

I then need to pass this array to a procedure (ByRef) as I need to change the size of the array and populate it

Public Sub MyProcedure(ByRef Harry As String)
'Get vC
Redim Harry(vC) as string
For vIndex = 0 to vC -1
Harry(vC) = 'Something
Next
End Sub

What I am getting is a Compile Error: Expected Array at the line that ReDims the Array.
Can anyone tell me where I'm going wrong?

Tony
 
Pass Harry as a variant. Post to NG in PLAIN TEXT
Hi Guys,

I need some help in passing arrays to procedures. In my main event I have create an array as in:

Dim Harry(1) as String
Call MyProcedure (Harry)

I then need to pass this array to a procedure (ByRef) as I need to change the size of the array and populate it

Public Sub MyProcedure(ByRef Harry As String)
'Get vC
Redim Harry(vC) as string
For vIndex = 0 to vC -1
Harry(vC) = 'Something
Next
End Sub

What I am getting is a Compile Error: Expected Array at the line that ReDims the Array.
Can anyone tell me where I'm going wrong?

Tony
 
Tony Wainwright said:
Hi Guys,

I need some help in passing arrays to procedures. In my main event I
have create an array as in:

Dim Harry(1) as String
Call MyProcedure (Harry)

I then need to pass this array to a procedure (ByRef) as I need to
change the size of the array and populate it

Public Sub MyProcedure(ByRef Harry As String)
'Get vC
Redim Harry(vC) as string
For vIndex = 0 to vC -1
Harry(vC) = 'Something
Next
End Sub

What I am getting is a Compile Error: Expected Array at the line that
ReDims the Array.
Can anyone tell me where I'm going wrong?

First, you aren't declaring Harry as an array in your procedure header.
It should be

Sub MyProcedure(ByRef Harry() As String)

Second, you didn't declare Harry originally as a dynamic array, so you
won't be able to ReDim it unless you change the original declaration
from
Dim Harry(1) as String

to

ReDim Harry(1) as String

or

Dim Harry() as String
 
Back
Top