Apologies if I am making some amateur mistakes, but I am new to VBA.
I'm trying to populate an array declared inside of a class as a property, but something's going wrong. After much searching I have two questions that I can't seem to find anywhere else:
1 - Is there a simpler way to accomplish saving data to an array-like structure that I can pass to functions from a sub? The array-like structure needs to be resizable because I will not know how many components I will add until each iteration of a loop checks those conditions.
2 - How do I correctly accomplish the passing of the array property in my class correctly to another function? It's frustrated me enough that I would like to know how it can be done if only to understand what I was doing wrong or, perhaps, what misunderstanding I had of the way VBA works.
Code structure follows:
I have declared a Segments
property inside of a CTask
class like this:
Private pSegments() As CSegment
Public Property Get Segments() As CSegment()
Segments = pSegments()
End Property
Public Property Get segment(index As Integer) As CSegment
segment = pSegments(index)
End Property
Public Property Let Segments(Value() As CSegment)
pSegments() = Value()
End Property
I pass the CTask
from a Sub
, where it is defined to populateTasks
using this code:
Dim tasks() As CTask
ReDim tasks(1 To 10)
Call populateTasks(tasks)
When I do this, the populateTasks
code receives it using the following code:
Function populateTasks(ByRef tasks() As CTask)
I then try to call another function from populateTasks
called populateSegments
like this:
Call populateSegments(tasks(icount).Segments)
I receive segments array inside populateSegments
like this:
Function populateSegments(ByRef Segments() As CSegment)
The last two code snippets are where the problem resides. The segments array is populating correctly inside the populateSegments
function, but when I check the array to see if it is empty just below the call to populateSegments
there isn't anything in the tasks(icount).segments
array. Thanks in advance for any help, and please let me know if more information is required.