Results 1 to 3 of 3

Thread: Releasing an array??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Posts
    70

    Question

    Hey,
    I have an array which is dynamic... ie...
    Code:
    Public PathsToExplore() As String
    I have a function that adds data to this array, then another which searches it.., the searching function uses UBound to tell if it has reached then end.. the problem is, If i add a large number of things to the array, then want to clear it and add a smaller number, ubound reports incorrectly and i get false entries.. how can i reset or release or clear or resize the array or such?

    Thanks
    Daniel Rose
    VB 5.0 Enterprise.
    irc:irc2.dynam.ac

    If TheCodeInTheSig() Is Not Lame() Then IDontKnowWhatIs()

  2. #2
    Junior Member
    Join Date
    Jul 2000
    Location
    Belfast
    Posts
    28
    I havn't tried this it is just a thought.

    Redim the array
    Code:
    ReDim PathsToExplore(0) 
    For i = 0 to x
    Redim Preserve PathsToExplore(UBound(PathsToExplore)+1)
    'Add your new data
    PathsToExplore(UBound(PathsToExplore)) = 'Value
    Next

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Erase myArray
    
    Erase frees the memory used by dynamic arrays. 
    Before your program can refer to the dynamic array again, 
    it must redeclare the array variable's dimensions using a 
    ReDim statement.
    
    
    The ReDimstatement is used to size or resize a dynamic array that 
    has already been formally declared using a Private, Public, or Dim 
    statement with empty parentheses (without dimension subscripts).
    
    You can use the ReDim statement repeatedly to change the number of 
    elements and dimensions in an array. However, you can't declare an 
    array of one data type and later use ReDim to change the array to 
    another data type, unless the array is contained in a Variant. 
    If the array is contained in a Variant, the type of the elements can 
    be changed using an As type clause, unless you’re using the 
    Preserve keyword, in which case, no changes of data type are permitted.
    
    If you use the Preserve keyword, you can resize only the last 
    array dimension and you can't change the number of dimensions at all. 
    For example, if your array has only one dimension, you can resize 
    that dimension because it is the last and only dimension. However, 
    if your array has two or more dimensions, you can change the size 
    of only the last dimension and still preserve the contents of the 
    array. The following example shows how you can increase the size of 
    the last dimension of a dynamic array without erasing any existing 
    data contained in the array.
    
    ReDim X(10, 10, 10)
    . . .
    ReDim Preserve X(10, 10, 15)
    
    Similarly, when you use Preserve, you can change the size of the 
    array only by changing the upper bound; changing the lower bound 
    causes an error.
    
    If you make an array smaller than it was, data in the eliminated 
    elements will be lost. If you pass an array to a procedure by reference
    , you can't redimension the array within the procedure.
    
    When variables are initialized, a numeric variable is initialized to 0,
    a variable-length string is initialized to a zero-length string (""), 
    and a fixed-length string is filled with zeros. Variant variables are 
    initialized toEmpty. Each element of a user-defined type variable is initialized as if it were a separate variable. A variable that refers to an object must be assigned an existing object using the Set statement before it can be used. Until it is assigned an object, the declaredobject variable has the special value Nothing, which indicates that it doesn't refer to any particular instance of an object.
    
    Caution   The ReDim statement acts as a declarative statement if 
    variable it declares doesn't exist atmodule level orprocedure level. 
    If another variable with the same name is created later, even in a 
    widerscope, ReDim will refer to the later variable and won't 
    necessarily cause a compilation error, even if Option Explicit is 
    in effect. To avoid such conflicts, ReDim should not be used as a 
    declarative statement, but simply for redimensioning arrays.
    
    Note   To resize an array contained in a Variant, you must explicitly 
    declare the Variant variable before attempting to resize its array.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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