Solved

VBA ByRef Passing Arrays

Posted on 2009-04-07
1
494 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
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 …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

739 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