Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: VBA Arrays and Functions


Message #1 by "Dave Loukola" <dave.loukola@H...> on Wed, 20 Nov 2002 21:50:39
Hi guys,

I seem to have misplaced some knowledge I have previously had.

I need to use an array as a argument for a function that does this:

function MyFunc(arg(1) as integer, arg(2) as integer) as integer
    if arg(1) = something then
       do this
    else if arg(2) = somethingelse then
       do this
    endif
end function

however, this doesn't seem to work and I don't know why.

Please help out if you can.


Dave
Message #2 by "Leo Scott" <leoscott@c...> on Wed, 20 Nov 2002 13:55:30 -0800
Function MyFunc(ByRef ArrayName() As Integer) As Integer
   If ArrayName(1) = something then
      do this
   ElseIf ArrayName(2)=somethingelse Then
	do this
   end if
   'Since this is a function we should return something?
End func

Dim intSomething as integer
Dim intArray(1 to 2) as Integer

intsomething=MyFunc(intArray)


|-----Original Message-----
|From: Dave Loukola [mailto:dave.loukola@H...]
|Sent: Wednesday, November 20, 2002 9:51 PM
|To: Access
|Subject: [access] VBA Arrays and Functions
|
|
|Hi guys,
|
|I seem to have misplaced some knowledge I have previously had.
|
|I need to use an array as a argument for a function that does this:
|
|function MyFunc(arg(1) as integer, arg(2) as integer) as integer
|    if arg(1) = something then
|       do this
|    else if arg(2) = somethingelse then
|       do this
|    endif
|end function
|
|however, this doesn't seem to work and I don't know why.
|
|Please help out if you can.
|
|
|Dave
|
Message #3 by "Dave Loukola" <dave.loukola@H...> on Wed, 20 Nov 2002 22:16:40
Thanks for the info Leo, I can see that being useful in the future. 
I did solve my problem though.  For anyone curious, I used:

Function MyFunc(paramArray arg() as variant)
    arg(0) = firstArg
    arg(1) = secondArg
End Function


Cheers


Dave

  Return to Index