Solved

VBA ByRef Passing Arrays

Posted on 2009-04-07
1
488 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Microsoft Office Customization Tool’s Outlook problem 12 78
SQL VB connection works in one PC and doesn't in another 15 58
Consumer laptop recommendation 6 67
Macro 6 50
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

867 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

15 Experts available now in Live!

Get 1:1 Help Now