I have a class with a property that will hold an array of objects.
I want to use the constructor of my class to start of with an empty array to which I will append to later on.
But i can’t seem to declare
myArrayOfObjects = Array()
Please do not post the same question in two or more channels.
In the IDE:
Create the property and set it as follows:
Name: myArrayOfObjects
Type: Object()
Default: // leave that empty
Scope: Public // or change it to the scope it needs to have
In code:
Dim myArrayOfObjects() As Object
In both cases the array will exist and have zero elements. You do not initialize an array with New.
[quote=207383:@Jan Verrept]I have a class with a property that will hold an array of objects.
I want to use the constructor of my class to start of with an empty array to which I will append to later on.[/quote]
[quote=207399:@Jan Verrept]So it can’t be done in code?
I wanted to initialize the existing property not create an extra variable[/quote]
What do you want to obtain by “initializing” ?
As a property myArrayOfObjects() As Object of your class it exists already. No need to dim it.
Just use the IDE to add a property to your class and you are done. Note the parenthesis that make the property an array.
You can then go
myArrayOfObjects.append(new CustomObject)
Add, remove, insert any object of your liking.
For instance :
myArrayOfObjects.append(new CustomObject)
myArrayOfObjects.insert(0, new Timer)
myArrayOfObjects.Remove(1)
The class is part of my applications model.
I connect the objects that make up the model in the constructor of each class
I also consider it good practice to initialize every (non-object) variable including arrays, hence my question.
Dim b As Boolean // implicitly set to False
Dim i As Integer // implicitly set to 0
Dim d As Double // implicitly set to 0.0
Dim s As String // implicitly set to ""
etc.
And for arrays:
Dim b() As Boolean // an empty array of Boolean
Dim b(-1) As Boolean // equivalent to the above
etc.