I have been using an awkward method to store and call my UDT arrays by key.
That is by making an array and corresponding collection for storing the array index and calling the content by key, please see my code below.
Is there better practice for this in VBA? That maybe can call array member by key without making additional variable (collection) to store/call the array index by key.
That is by making an array and corresponding collection for storing the array index and calling the content by key, please see my code below.
Is there better practice for this in VBA? That maybe can call array member by key without making additional variable (collection) to store/call the array index by key.
VBA Code:
Type tSampleType
Name As String
nData As Long
DataX() As Double
DataY() As Boolean
End Type
Sub SampleSub()
Dim ArrayA() As tSampleType
Dim ArrayA_ID As New Collection
Dim i As Long, Name As String, DataX As Double
'Store array
ReDim ArrayA(99)
For i = 0 To 99
With ArrayA(i)
.Name = "abc" & i
ArrayA_ID.Add i, .Name
nData = 1000
ReDim .DataX(nData - 1), .DataY(nData - 1)
'and so on
End With
Next i
'Calling array member by key
Name = "abc0"
i = ArrayA_ID(Name)
DataX = ArrayA(i).DataX(123)
End Sub