#2. I didn't need to pass it anything. This worked just as well:
Option Explicit
Sub testme()
Dim myArr As Variant
Dim iCtr As Long
myArr = BuildArray
For iCtr = LBound(myArr) To UBound(myArr)
MsgBox iCtr & ". " & myArr(iCtr)
Next iCtr
End Sub
Function BuildArray() As Variant
Dim iCtr As Long
ReDim SomeArray(1 To 52)
For iCtr = 1 To 52
SomeArray(iCtr) = iCtr & "--Hi there"
Next iCtr
BuildArray = SomeArray
End Function
This may make it easier to see how #4 works. Since myArr is a Variant (which
can hold anything) and BuildArray passes back an array), then myArr becomes an
array.
I guess it was more muscle memory than anything to pass it the parm--it wasn't
necessary and shouldn't have been passed.
I'm in the middle of the USA.
Cloudfall wrote:
>
> Hi again Dave,
>
> This worked in my application. I'm trying to figure out how it works. I
> think it works as follows:
>
> 1. When you declare "myArr" in the calling subprocedure "testme()", its
> just a variable and not an array yet.
> 2. When you call the function "BuildArray" you pass it the variable
> "myArr" and "BuildArray" turns the variable "myArr" into a variable
> array when it re-declares it as such.
> 3. You then assign the created array to the function "BuildArray" which
> is passed back to the calling variable "myArr".
> 4. What I don't understand is how the variable "myArr" turns into a
> variable array when it hasn't been declared as such!
> 5. I understand the rest of the above.
>
> (By the way, are you Australian? If not, where are you from?)
>
> Thank you for the trouble you have gone to to help me. I really
> appreciate your expertise in matters of VBA.
>
> Regards,
>
> Terry.
--
Dave Peterson
|