Passing Arrays to procedures

  • Thread starter Tony Wainwright
  • 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
 
P

Paul Overway

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
 
D

Dirk Goldgar

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top