|
-
Jul 12th, 2000, 09:57 PM
#1
Thread Starter
Lively Member
Ok, Here is my problem, I'm going to be needing an array, but, i don't know how many items are going to be in the array until later (after the program loads), but, i need the array to be global within that form, so I can't set it in the General Declarations
Question:
How can I load an array that is global (meaning I can call MyArray(MyItem) from anywhere inside that form to get the value) to that form and not to a procedure later in program (after it loads)
The user might have 1 item to 100000000 items inside this array.
I hope i haven't confused any of you.
Thanks in advance,
Ryan
-
Jul 12th, 2000, 10:15 PM
#2
Hyperactive Member
Hopefully, you've seriously exaggerated your upper limit or intend running your app on a PIII/900 Blackbird, else you definitely do not want to use an array. When you start adding dimensions to an array, the total amount of storage needed by the array increases dramatically. This is especially true for a multidimensional arrays. 'Nuff said, use 'em with care (be especially careful with Variant arrays, because they're larger than arrays of other data types).
You declare a dynamic array just as you would declare a fixed*size array, but without specifying dimension sizes within the parentheses following the array name, for example:
Dim RyanArray() As Integer
Then somewhere in your procedure/function, allocate the actual number of elements with a ReDim statement:
ReDim RyanArray(X + 1)
You use the Preserve keyword to change the size of an array without losing the data in it. You can enlarge an array by one element without losing the values of the existing elements:
ReDim Preserve RyanArray(UBound(RyanArray) + 1)
Hope this helps 
-
Jul 13th, 2000, 12:29 AM
#3
Hyperactive Member
If the array can change that dynamically I would consider using a collection instead.
The added benefit is that you can place a "key" on each of the elements in the collection allowing you to effectively perform "Associative Array" type qualities.
Just a thought
-
Jul 13th, 2000, 03:02 AM
#4
Lively Member
The problem with collections is that they tend to be slower than the array (at least that's my experience with them), and with that amount of data, I would suggest sticking with an array. But otherwise I agree that collections are quite lovely.
//Anders
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
|