Announcement

Collapse
No announcement yet.

Redim Preserve not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mike Doty
    replied
    Sorta related using a 2-dimensional array.
    Correct way to resize grid based on the number of rows:
    REDIM PRESERVE A(cols,rows) AS STRING 'change number of rows
    REDIM PRESERVE A(x,y) AS STRING 'change number of rows 'Cartesian

    I've done this backward too many times with REDIM PRESERVE A(rows,cols)
    or accessed the array forgetting that the second dimension should be the row.
    Last edited by Mike Doty; 26 Jan 2009, 01:31 PM.

    Leave a comment:


  • Michael Mattias
    replied
    That time is coming....(Undimensioned arrays will have element 0, aka LBOUND = 0, but UBOUND will be -1)
    You don't test for dimensioned/not-dimensioned with LBOUND and UBOUND ; you use ARRAYATTR with 'attrnum' = 0.

    If the array is dimensiond, THEN you can inquire about the bounds.

    MCM

    Leave a comment:


  • Cliff Nichols
    replied
    used to have that same blind spot. A good number of years ago I just made a decision that "all arrays used shall have an LBOUND of zero, even if element zero is not used."

    It's kept me out of trouble for a long time.
    That time is coming....(Undimensioned arrays will have element 0, aka LBOUND = 0, but UBOUND will be -1)

    Not sure about what a quick test would reveal, but hey its 10 seconds or less for one to find out

    Leave a comment:


  • Michael Mattias
    replied
    Re...
    Code:
    ReDim Preserve Record_Info(UBound(Record_Info()) + 1)
    vs
    ReDim Preserve Record_Info(1 To UBound(Record_Info()) + 1)
    I used to have that same blind spot. A good number of years ago I just made a decision that "all arrays used shall have an LBOUND of zero, even if element zero is not used."

    It's kept me out of trouble for a long time.

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Originally posted by Eric Pearson View Post
    Without seeing more code it's hard to say.

    What do the original DIMs look like?
    ReDim Record_Info(1 To fRecords) 'original dim
    Are they Global arrays, or Local?
    Global
    What does ERR tell you?
    -- Eric
    Ah, silly me. I never looked. At your perceptive promting Dear Highest of PB Lords, I gave Err a shot and immediately found I needed to use
    Code:
     
    ReDim Preserve Record_Info(1 To UBound(Record_Info()) + 1)
    Thanks max, Eric. Would you believe I went to bed after posting above (see time) and just got up to whiz. Now going back to bed. {grin}

    =========================================================
    "To love oneself is the beginning of a lifelong romance"
    Oscar Wilde (1854-1900)
    =========================================================

    Leave a comment:


  • Eric Pearson
    replied
    Without seeing more code it's hard to say.

    What do the original DIMs look like? Are they Global arrays, or Local?

    What does ERR tell you?

    -- Eric

    Leave a comment:


  • Gösta H. Lovgren-2
    started a topic Redim Preserve not working

    Redim Preserve not working

    Weary old eyes, getting (is) late, ... . Can someone (please Lords of PB) spot what's wrong here? The first array doesn't expand while the second does.

    '
    Code:
         s3$ = Using$(" #,   #,   #, ", UBound(Record_Info()), UBound(Index_Array$()), rn)
      ? s3$,,"Don't Save yet!"
        
        ReDim Preserve Record_Info (UBound(Record_Info()) + 1)'<<< Does not increase
        ReDim Preserve Index_Array$(UBound(Index_Array$()) + 1)'<<< Does increase
        rn = UBound(Record_Info())'<<< Does not increase
             s3$ = Using$(" #,   #,   #, ", UBound(Record_Info()), UBound(Index_Array$()), rn)
      ? s3$,,"Don't Save yet!"
    '
    =====================================================
    To disagree with three-fourths of the British public
    is one of the first requisites of sanity.
    Oscar Wilde
    =====================================================
Working...
X