|
-
Jul 11th, 2005, 01:02 PM
#1
Thread Starter
No place like 127.0.0.1
[RESOLVED] Passing An Array to a Funcion
Yesterday I asked how to have a function pass an arrayas its return value. Now I need to know how to pass the array back to a function. Here is what I currently have, but doesn't this make the variable a variant?
VB Code:
Public Function MyFunc(SourceArray) As String()
But if I try this then I get s syntax error:
VB Code:
Public Function MyFunc(SourceArray As String()) As String()
Does ParamArray have anything to do with it? I tried using this (without having any idea what I was doing), but to no avail. What does ParamArray do anyway?
-
Jul 11th, 2005, 01:03 PM
#2
Re: Passing An Array to a Funcion
just guessing....but
VB Code:
Public Function MyFunc(SourceArray() As String) As String()
??
-
Jul 11th, 2005, 01:10 PM
#3
Thread Starter
No place like 127.0.0.1
Re: Passing An Array to a Funcion
I tried that, and it didn't give me a syntax error, but I never got around to running the program with that format because I thought it would give me an error.
The first line of code in my original post WORKS, but I think it makes the variable a variant and is therefor obviously slow and I would like to improve it if I can.
-
Jul 11th, 2005, 01:21 PM
#4
Re: Passing An Array to a Funcion
kfcSmitty - good guess... That is the correct declaration.
eyeRmonkey - ParamArray allows you to pass multiple arguments to a procedure which VB will then place into an array. The ParamArray argument can only be of type Variant, must be the last one in the procedure's argument list and is always considered optional.
VB Code:
Public Function CountNumbers(ParamArray Numbers() As Variant) As Long
Dim lngIdx As Long
For lngIdx = LBound(Numbers) To UBound(Numbers)
CountNumbers = CountNumbers + Numbers(lngIdx)
Next
End Function
Private Sub Form_Load()
Debug.Print CountNumbers(1, 4.5, 7, 100)
Debug.Print CountNumbers(84, 2)
Debug.Print CountNumbers
End Sub
-
Jul 11th, 2005, 01:28 PM
#5
Thread Starter
No place like 127.0.0.1
Re: Passing An Array to a Funcion
Ok, will use Smitty's way. Thanks guys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|