Уважаемые, здравствуйте. Как получить элемент коллекции или словаря из класса. Пример: Есть классы: Table
Код
Option Explicit
Private obgRows As Rows
Public Property Get Rows(Optional Index As Long) As Rows
Set Rows = obgRows
End Property
Public Property Let Rows(Optional Index As Long, rows_ As Rows)
Set obgRows = rows_
End Property
Private Sub Class_Initialize()
Set obgRows = New Rows
End Sub
Rows
Код
Option Explicit
Private Coll_ As New Collection
Public Property Get Item(Index_ As Long) As Long
Index = Coll_(CStr(Index_))
End Property
Public Function Add(Index_ As Long)
Coll_.Add Index_, CStr(Index_)
End Function
Модуль с процедурой
Код
Sub test()
Dim cl As New Table
Dim value As Variant
Call cl.Rows.Add(1)
Call cl.Rows.Add(2)
value = cl.Rows.Item(1)
End Sub
Сейчас я получаю значение из коллекции в классе Rows через свойство Item. А хотелось бы получать нужный item напрямую из Rows: value = cl.Rows(1)
Пробовал решить задачу через атрибут(разместил его в Item) но проблема в том, что в свойство item не приходит значение. Например: cl.Rows(1) -> в Table.Rows Index=1, затем переходим в Rows.Item. а здесь уже Index=0