Object: smart way to assign a value as for an array?

  • Thread starter Thread starter Charles
  • Start date Start date
C

Charles

Hello

quick question: is there a smart way to define a procedure to do the
same thing as a "public let", but with the array syntax?

i.e. you can easily do MyObject.MyValue = 10 with a "public let", but
is there a way to do:

MyObject.MyArray(3)=10

Thanks in advance
Charles
 
And since Christmas is coming, what about having also the flexibility
to use it in the other way, i.e. xx = MyObject.MyArray(3)
 
Based on a wild guess as to at what you're doing, arrays cannot be Public in
a Class module. Maybe something like -

' code in Class1
Private arr(1 To 10) As Long

Public Property Let propArray(idx As Long, n As Long)
arr(idx) = n
End Property

Public Property Get propArray(idx As Long) As Long
propArray = arr(idx)
End Property


' code in a normal module
Dim myObject As Class1

Sub test()
Set myObject = New Class1

myObject.propArray(3) = 10

MsgBox myObject.propArray(3)

Set myObject = Nothing

End Sub


Regards,
Peter T
 
Peter

thanks for your answer. This is exactly what I wanted to do. I wasn't
aware that by defining the procedure "Public Property Let
propArray(idx As Long, n As Long)" you could also use it by doing
"myObject.propArray(3) = 10" instead of something like
"myObject.propArray(3,10)" . It is much more intuitive to use your
way.

Thanks very much!

Charles
 

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

Back
Top