VBA -- Property Get

J

jfp

Supposedly Property Get can return an array -- but i cannot figure out
how to use this -- i get an "Cannot assign to array" when i try to do
something like
myArray = GetXXX()

How does this work ?
 
R

rkc

jfp said:
Supposedly Property Get can return an array -- but i cannot figure out
how to use this -- i get an "Cannot assign to array" when i try to do
something like
myArray = GetXXX()

How does this work ?

In a class module?

<clsPassArray>
Private arry() As String

Public Property Get TheArray() As String()
TheArray = arry
End Property


Private Sub Class_Initialize()
ReDim arry(6)
arry(0) = "Once"
arry(1) = "upon"
arry(2) = "a"
arry(3) = "time"
arry(4) = "in"
arry(5) = "the"
arry(6) = "west."
End Sub

</clsPassArray>

<Form Test>

Private Sub Command0_Click()
Dim ar As clsPassArray
Dim s() As String
Dim i As Integer
Set ar = New clsPassArray

s = ar.TheArray
Text0.Value = ""

For i = 0 To UBound(s)
Text0.Value = Text0.Value & i & ": " & s(i) & vbCrLf
Next

Set ar = Nothing
End Sub

</Form Test>
 
J

jfp

Ahhh ...
I had an example similar to yours, but i knew (by design) the size of
the array. So, in the part that calls the function, instead of your
Dim s() As String
i had something like
Dim s(4) As String
This led to the "Cannot assign to array" error during compilation.
Any idea why this is ?

Also -- i was surprised that your
s = ar.TheArray
worked. I thought the () were needed since it is a function call.
Apparently not, but
s = ar.TheArray()
works equally well.

Thanks !
-=-=-=-=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top