Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 10th, 2006, 03:24 PM
Authorized User
 
Join Date: Apr 2004
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))
                  or
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?

example:
Sub OtherSubRoutine(strArray(9) As String)
              or
Sub OtherSubRoutine(strArray() As String)
              or
Sub OtherSubRoutine(ReDim Preserve strArray() As String)


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

Thanks,
Don

 
Old May 11th, 2006, 03:17 AM
Authorized User
 
Join Date: Apr 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old May 11th, 2006, 09:39 AM
Authorized User
 
Join Date: Apr 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Else
    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.

Don






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.