Announcement

Collapse
No announcement yet.

multicolumn ARRAY SORT

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

  • multicolumn ARRAY SORT

    I will be reading a CSV file with 15 columns and x (normally about 500) rows. It will be hard to tell visually whether I am getting the results I expect, so I wanted to come here first. The entire array will be DIMed starting from 1,1 rather than 0,0.

    I have to sort first on column 3, then sort on column 12, and finally sort on column 2. I do not want any columns re-arranged. The data in column 5 will stay in column 5, but the entire row would move up or down in the array as the columns require.

    How should I set up these ARRAY SORTs to be sure I get the intended result?
    Erich Schulman (KT4VOL/KTN4CA)
    Go Big Orange

  • #2
    I would just build a sort key using a single dimension array...
    Code:
    TYPE SORTKEY
       Col3    AS STRING * whatever
       Col12  AS STRING  * whatever
       Col2    AS STRING  * whatever 
    END TYPE
    
      LOCAL SK () AS SORTKEY , CSV() AS STRING
    
      hFile = FreeFile 
      OPEN csvFile FOR INPUT AS hFile 
      FILESCAN hfile, RECORDS TO nRec 
      REDIM   CSV(1 TO nrec)     ' I would use zero based personally 
      REDIM   SK (1 to Rec) 
      LINE   INPUT #Hfile, CSV() 
      CLOSE hFile 
      FOR Z = 1 TO nRec 
         SK(Z).Col3 = PARSE$(CSV(Z),3) 
         SK(Z).Col12 = PARSE$(CSV(Z),12) 
         SK(Z).Col2= PARSE$(CSV(Z),2) 
      NEXT
      ARRAY SORT SK(), TAGARRAY CSV()
    CSV() is now in order as requested. Do what you will with it.

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment

    Working...
    X