Results 1 to 4 of 4

Thread: Array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    California
    Posts
    115

    Post

    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

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    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


  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    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

  4. #4
    Lively Member
    Join Date
    Jul 2000
    Location
    Vaxjo, Sweden
    Posts
    85
    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
  •  



Click Here to Expand Forum to Full Width