What is the correct way to pass an Array into a function

Tech-Archive recommends: Fix windows errors by optimizing your registry



All,
Could somebody please help me figure out how to pass an array into a
function. I've been trying different variations of this code, but
continue to have a problem when I attempt to pass myArray() into
fnDisplayMSG... I know that fnTmp is correct, except for the fact that
I can't figure out how to declare myArray(), because when I call the
MessageBox from within the function, the function works, however when I
use the Call fnDisplayMSG(x, myArray()) I receive an error.

Any help on declaring an array or correctly passing an array into a
function would be greatly appreciated. Thanks in advance. - CES

Public Function fnDisplayMSG(x As Integer, myArray() As String) As
String
MsgBox (myArray(x))
End Function

Public Function fnTmp(x As Integer) As String

'Dim myArray() As String
myArray = Array("Value 1", "Value 2", "Value 3", "Value 4", "Value 5")

Call fnDisplayMSG(x, myArray())
'MsgBox (myArray(x))
End Function

.



Relevant Pages

  • Re: Type Mismatch Error
    ... ' Read text file into an array #1 ... Dim InString As String, MyArray As Variant ... ' Debug.Print MyArray ' type mismatch error. ...
    (microsoft.public.vb.general.discussion)
  • Re: Join numbers to form Array calculation
    ... > passed the numbers in the array. ... >> Public Function GetNumbers As String) as Decimal ... >>> Dim MyArray() As String, ...
    (microsoft.public.access.modulesdaovba)
  • Re: Unique an array of strings
    ... Public Function Unique(ByVal List As String()) As String ... ToArray places all items in the ArrayList into an array and returns the ... The element Type of the destination array to create and copy elements ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Array Optimization
    ... Public Function returnPoint ... As String Dim strReturn As String = "" ... Each item references the Point (or, with> 1 point at a location, ... Or, use an array of arrays ), using the x coordinate to ...
    (microsoft.public.dotnet.languages.vb)
  • Re: String Array Optional einbinden
    ... auf die Idee einfach ein Variant zu nehmen und diesen zum String ... Array zu deklarieren bin ich auch schon kommen. ... MyFunction(Optional MyArray() as Variant) ...
    (microsoft.public.de.access)