Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBA ByRef Passing Arrays

Posted on 2009-04-07
1
Medium Priority
?
507 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 93

Accepted Solution

by:
Patrick Matthews earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
Suggested Courses

715 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