Solved

VBA ByRef Passing Arrays

Posted on 2009-04-07
1
485 Views
Last Modified: 2012-05-06
I'm getting a ByRef error, anyone know why? I'm pretty new to pointers.
Sub test()

Dim staticarray(3) As String

staticarray(0) = "H"

staticarray(1) = "E"

staticarray(2) = "L"

staticarray(3) = "O"
 
 

Call testfunc(staticarray)

i = 0

Do

Debug.Print staticarray(i)

i = i + 1

Loop Until i = 4

End Sub
 

Sub testfunc(ByRef staticarray As String)

staticarray(0) = "JACK"

staticarray(1) = "O"

staticarray(2) = "LANTERN"

End Sub

Open in new window

0
Comment
Question by:allenlo77
1 Comment
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
ID: 24088250
Change:

Sub testfunc(ByRef staticarray As String)

to:

Sub testfunc(ByRef staticarray As Variant)

As you wrote it, testfunc was expecting a scalar variable, not an array.

Patrick
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now