|
-
Apr 21st, 2009, 05:11 AM
#1
Thread Starter
Junior Member
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?
Last edited by albo; Apr 21st, 2009 at 07:50 AM.
-
Apr 21st, 2009, 05:22 AM
#2
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
-
Apr 21st, 2009, 06:09 AM
#3
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.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Apr 21st, 2009, 07:21 AM
#4
Re: Pushing to an Array
A collection might be more appropriate.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|