Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 10th, 2006, 03:24 PM
Authorized User
Join Date: Apr 2004
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing an array to a Sub or Function

How do I pass an array to a Sub or Function?

Lets say I have a single dimensional array with from 0 to 10.

When passing to an array to a sub do I have to specify the array number as in the example below?

Call OtherSubRoutine(strArray(9))
Call OtherSubRoutine(strArray())

will the second option pass all values or give me an error?

and how do I receive in the sub that is being called?

Sub OtherSubRoutine(strArray(9) As String)
Sub OtherSubRoutine(strArray() As String)
Sub OtherSubRoutine(ReDim Preserve strArray() As String)

I'm confused. What to do? Please advise...


Reply With Quote
  #2 (permalink)  
Old May 11th, 2006, 03:17 AM
Authorized User
Join Date: Apr 2006
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts

All you need to do is put the name of the array after the sub/function name without parentheses:

      myfunc myarray

You do have to enclose the entire parameter list in parentheses if you are calling a function and using it's return value:

      MsgBox "myfunc returned " & myfunc( myarray )

Hope this clear things up for you.
Reply With Quote
  #3 (permalink)  
Old May 11th, 2006, 09:39 AM
Authorized User
Join Date: Apr 2004
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts

ok thanks,
You answered half my question and I appreciate it. So the other half is...how do I receive an array in the arguments section of the called sub/function? Can you also give an example to show me how to return the array values from within the function that is called. For example: with normal functions I might want to know if the value of something is true or false so I have my function look like this:

Function SomeFunctionEx(strArgBeingPassed as String) As Boolean

If (strArgBeingPassed = "Something") Then
    SomeFunctionEx = True
    SomeFunctionEx = False
End If

End Function

Now if I wanted to return an array from a function that is similar to the above example then is the below syntax correct?

Function SomeArrayFunctionEx(strArgBeingPassed as String) As String

'There is a bunch of code in here that does stuff and populates the array.

'Now I return the array.
SomeArrayFunctionEx = strArgBeingPassed

End Function

Does the above example return the entire array to the sub or function that called it?

Thanks for you help with this subject.


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing an array from module to form ftm Excel VBA 2 March 8th, 2007 07:39 AM
passing parameter array Maryann BOOK: Access 2003 VBA Programmer's Reference 0 December 4th, 2006 10:56 AM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM
Passing an array in a Sub krunch97 VB.NET 2002/2003 Basics 1 May 4th, 2004 01:29 PM
Passing an Array of Strings to a WebService rmau Excel VBA 0 October 27th, 2003 03:59 PM

All times are GMT -4. The time now is 11:49 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.