Solved

VBA ByRef Passing Arrays

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

623 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