-
Pushing to an Array
Sorry if this is a really obvious question, ive searched the forums etc but cant find a solution.
I'm creating an array like this:
Code:
Dim ConnectionsArray() As String
later on i just want to PUSH an item to the end of the array. I dont really want to reference the array number at all.
For example:
Code:
ConnectionsArray.push(myvar)
Is this possible?
-
Re: Pushing to an Array
Code:
Private Sub Push(ByRef arr() as string, ByVal value as String)
Redim Preserve arr(ubound(arr)+1)
arr(ubound(arr)) = value
End Sub
And you use it like this:
Code:
Push ConnectionsArray, MyVar
-
Re: Pushing to an Array
ReDim Preserving is obscenely slow for large arrays since it has to copy everything you already have. If this is an issue you can, for example, add 10 blank entries, extending the array only when necessary.
-
Re: Pushing to an Array
A collection might be more appropriate.