Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Passing Arrays to Subroutines


Message #1 by "Gregory Serrano" <SerranoG@m...> on Fri, 18 Oct 2002 17:47:42
I'm having a brain fart.  What's the correct syntax for passing an array 
to a subroutine?  I don't use arrays often enough to remember.  The 
following doesn't work:

   Private Sub Whatever_AfterUpdate

      Dim strName(25) as String

      Call DoSomething(strName, 25)

   End Sub


   Public Sub DoSomething(strName as String, bytArraySize as Byte)

      Dim bytX as Byte

      For bytX = 0 to bytArraySize - 1
         'blah blah...
      Next bytX

   End Sub


What should be in the call's () and in the subroutine's ()?  Thanks.

Greg


Message #2 by "Bob Bedell" <bobbedell15@m...> on Fri, 18 Oct 2002 17:32:29 +0000
Hi Greg,

I used an integer array to do a little math. The following prints the
numbers 1 through 26 to the immediate window. Remember that arrays are
0 based. Set the lower bound to 1 using Option Base.

'~~~~~~~~~~Start~~~~~~~~~~

Sub Whatever()
  'Declare static array with 26 elements
  Dim aintIntegers(25) As Integer

  ' Pass whole array call-by-reference(default)
  Call DoSomething(aintIntegers())
End Sub

Sub DoSomething(a() As Integer)
  Dim x As Integer
  For x = LBound(a) To UBound(a)
    a(x) = x + 1
    Debug.Print a(x)
  Next x
End Sub

'~~~~~~~~~~Stop~~~~~~~~~~


Best,

Bob



>From: "Gregory Serrano" <SerranoG@m...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Passing Arrays to Subroutines
>Date: Fri, 18 Oct 2002 17:47:42
>
>I'm having a brain fart.  What's the correct syntax for passing an array
>to a subroutine?  I don't use arrays often enough to remember.  The
>following doesn't work:
>
>    Private Sub Whatever_AfterUpdate
>
>       Dim strName(25) as String
>
>       Call DoSomething(strName, 25)
>
>    End Sub
>
>
>    Public Sub DoSomething(strName as String, bytArraySize as Byte)
>
>       Dim bytX as Byte
>
>       For bytX = 0 to bytArraySize - 1
>          'blah blah...
>       Next bytX
>
>    End Sub
>
>
>What should be in the call's () and in the subroutine's ()?  Thanks.
>
>Greg
>
>


_________________________________________________________________
Unlimited Internet access for only $21.95/month.  Try MSN! 
http://resourcecenter.msn.com/access/plans/2monthsfree.asp

Message #3 by "Bob Bedell" <bobbedell15@m...> on Fri, 18 Oct 2002 18:02:29 +0000
Using

    For x = LBound(a) To UBound(a) - 1

also emulates setting Option Base to 1


_________________________________________________________________
Unlimited Internet access for only $21.95/month.  Try MSN! 
http://resourcecenter.msn.com/access/plans/2monthsfree.asp

Message #4 by JOHNWARDBELL@a... on Sat, 19 Oct 2002 05:23:13 EDT
In a message dated 10/18/02 5:37:18 PM GMT Daylight Time, 
SerranoG@m... writes:


> 
> 
>       Call DoSomething(strName, 25)
> 

Try
       

      Call DoSomething()

john


  Return to Index