Solved

VBA ByRef Passing Arrays

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Office2007 Training Material Required 2 46
Generating a graph via Excel 3 39
audit logs in excel spreadsheet 1 90
ms office troubleshooting for users 8 42
Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
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 video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
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.

810 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