![]() |
Object: smart way to assign a value as for an array?
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 |
Object: smart way to assign a value as for an array?
Forgot to mention that I am using VBA
|
Object: smart way to assign a value as for an array?
And since Christmas is coming, what about having also the flexibility
to use it in the other way, i.e. xx = MyObject.MyArray(3) |
Object: smart way to assign a value as for an array?
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 "Charles" wrote in message oups.com... 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 |
Object: smart way to assign a value as for an array?
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 |
All times are GMT +1. The time now is 01:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com