Announcement

Collapse
No announcement yet.

Redim Preserve not working

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

  • 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
    =====================================================
    It's a pretty day. I hope you enjoy it.

    Gösta

    JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
    LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

  • #2
    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
    "Not my circus, not my monkeys."

    Comment


    • #3
      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([COLOR=red]1 To[/COLOR] 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)
      =========================================================
      It's a pretty day. I hope you enjoy it.

      Gösta

      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

      Comment


      • #4
        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.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          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
          Engineer's Motto: If it aint broke take it apart and fix it

          "If at 1st you don't succeed... call it version 1.0"

          "Half of Programming is coding"....."The other 90% is DEBUGGING"

          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

          Comment


          • #6
            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
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              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.
              The world is full of apathy, but who cares?

              Comment

              Working...
              X