Announcement

Collapse
No announcement yet.

Array Sort problem

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

  • Array Sort problem

    I'm trying a sort a mailling list. The code below works on trivial amounts
    of data, on larger sets the namearray outputs correctly but the mailarray
    is corrupt. Free memory is 285,024 bytes before the REDIM statements.

    TYPE MailHeader
    NumIn AS LONG
    NumSort AS LONG
    DefCity AS STRING * 15
    DefState AS STRING * 2
    DefZip AS STRING * 5
    DefSuf AS STRING * 25
    Junk AS STRING * 45
    END TYPE

    TYPE MailRecord
    FullName AS STRING * 25
    Address AS STRING * 30
    City AS STRING * 15
    State AS STRING * 2
    Zip AS STRING * 9
    Code AS STRING * 1
    Deleted AS STRING * 1
    Acct AS STRING * 6
    EntryDate AS INTEGER
    Junk AS STRING * 9
    END TYPE

    DIM NameArray(1) AS STRING * 25
    DIM HUGE MailArray(1) AS MailRecord

    IF FRE(-1) > ((LEN(MailArray(1).FullName) * MailH.NumIn) + (LEN(MailArray(1)) * MailH.NumIn)) THEN
    REDIM NameArray (MailH.NumIn)
    REDIM MailArray (MailH.NumIn)
    i = 1
    j = 1
    WHILE i <= MailH.NumIn
    CALL ReadRecord(FileNum,"",VARPTR32(MailArray(j)),i+1,LEN(MailArray(1)),%rNone)
    IF MailArray(j).Deleted <> "Y" THEN
    NameArray(j) = MailArray(j).FullName
    INCR j
    END IF
    INCR i
    WEND
    MailH.NumSort = j - 1
    MailH.NumIn = MailH.NumSort
    CALL WriteRecord(FileNum,"",VARPTR32(MailH),1,LEN(MailH),%rNone)
    TempFileNum = OpenFile ("Nametest.dat",3,3,1,25) 'Only used for debugging
    REDIM PRESERVE NameArray(MailH.NumSort)
    REDIM PRESERVE MailArray(MailH.NumSort)
    ARRAY SORT NameArray() ,COLLATE UCASE ,TAGARRAY MailArray()
    FOR i = 1 TO MailH.NumIn
    CALL WriteRecord(TempFileNum,"",VARPTR32(Namearray(i)),i,25,%rNone)
    CALL WriteRecord(FileNum,"",VARPTR32(MailArray(i)),i+1,LEN(MailArray(1)),%rNone)
    NEXT
    CloseFile TempFileNum
    SETEOF #FileNum
    ERASE NameArray,MailArray
    END IF


    ------------------

  • #2
    It's not really possible to determine the problem from your snippet without being able to exactly duplicate the results.

    Please ZIP and email the complete test code and data files to Tech Support and we'll take a look.

    Thanks!


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance,

      This sounds familiar!!!!



      ------------------
      C'ya
      d83
      C'ya
      Don

      http://www.ImagesBy.me

      Comment


      • #4
        Code:
        DIM HUGE MailArray(1) AS MailRecord
        IF FRE(-1) > ((LEN(MailArray(1).FullName) * MailH.NumIn) + (LEN(MailArray(1)) * MailH.NumIn)) THEN
          REDIM NameArray (MailH.NumIn)
          REDIM MailArray (MailH.NumIn)
        Unless I remember incorrectly, either an array is HUGE or it ain't and you can't switch back and forth like this without getting strange results..

        MCM




        [This message has been edited by Michael Mattias (edited December 11, 2002).]
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          REDIM does not change the array type, so that is not the problem here.

          In my brief tests, the size of the HUGE tagarray is possibly the cause of the problem, but I have yet to see and test the actual code.



          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Here's the code w/o all the library routines, still produces the same output as the
            full program.

            Code:
            $CPU 80386
            $COMPILE EXE
            $ERROR ALL ON
            $OPTIMIZE SIZE
            $LIB ALL OFF
            $STACK 5120
            OPTION BASE 1
            
            TYPE MailHeader
              NumIn    AS LONG
              NumSort  AS LONG
              DefCity  AS STRING * 15
              DefState AS STRING * 2
              DefZip   AS STRING * 5
              DefSuf   AS STRING * 25
              Junk     AS STRING * 45
            END TYPE
            
            TYPE MailRecord
              FullName  AS STRING * 25
              Address   AS STRING * 30
              City      AS STRING * 15
              State     AS STRING * 2
              Zip       AS STRING * 9
              Code      AS STRING * 1
              Deleted   AS STRING * 1
              Acct      AS STRING * 6
              EntryDate AS INTEGER
              Junk      AS STRING * 9
            END TYPE
            
            DIM FileName AS STRING,FileNum AS INTEGER,i AS LONG,j AS LONG
            DIM TempFileName AS STRING,TempFileNum AS INTEGER
            DIM MailH AS MailHeader
            DIM NameArray(1) AS STRING * 25
            DIM HUGE MailArray(1) AS MailRecord
            
            FileName = "ADCMAIL" + COMMAND$ + ".DAT"
            FileNum = FREEFILE
            
            OPEN FileName FOR RANDOM ACCESS READ WRITE SHARED AS FileNum LEN = LEN(MailH)
            GET #FileNum, 1, MailH
            
            IF FRE(-1) > ((LEN(MailArray(1).FullName) * MailH.NumIn) + (LEN(MailArray(1)) * MailH.NumIn)) THEN
              PRINT "Free Memory " + STR$(FRE(-1))
              REDIM NameArray (MailH.NumIn)
              REDIM MailArray (MailH.NumIn)
              i = 1
              j = 1
              WHILE i <= MailH.NumIn
                GET #FileNum, i+1, MailArray(j)
                IF MailArray(j).Deleted <> "Y" THEN
                  NameArray(j) = MailArray(j).FullName
                  INCR j
                END IF
                INCR i
              WEND
              MailH.NumSort = j - 1
              MailH.NumIn = MailH.NumSort
              PUT #FileNum, 1, MailH
              TempFileName = "NAMETEST.DAT"
              TempFileNum = FREEFILE
              OPEN TempFileName FOR RANDOM ACCESS READ WRITE SHARED AS TempFileNum LEN = LEN(MailArray(1).FullName)
              REDIM PRESERVE NameArray(MailH.NumSort)
              REDIM PRESERVE MailArray(MailH.NumSort)
              ARRAY SORT NameArray() ,COLLATE UCASE ,TAGARRAY MailArray()
              FOR i = 1 TO MailH.NumIn
                PUT #TempFileNum, i, NameArray(i)
                PUT #FileNum, i+1, MailArray(i)
              NEXT
              CLOSE
            ELSE
              PRINT "Not enough memory"
            END IF

            Comment


            • #7
              Thanks Billy. The ZIP you sent to Tech Support is just fine as it contained the actual test data to complement the code.

              Thanks again!


              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment

              Working...
              X