My understanding of the SORTLIB documentation is that the sorting proceeds based on the values in a row of the array. But I want to sort the array based on the content of a column. To do this, I do a transposition of the array so I can choose a row (instead of a column) as the key of the sort.
The following code makes this more tangible. When executed you will see 4 times an array content.
The first is the original array, still to be sorted. I want to sort all rows based upon the values in column 3.
The second is the transposed array, still to be sorted.
The third one is the transposed array, after sorting based upon the data in row 3
The fourth is the result of transposing the third one. This delivers the original array but sorted based on the content of column 3
This effectively gives me the result I'm looking for. So I have no immediate problem.
Still, I feel uncomfortable because I think I'm not correctly using SORTLIB.
Question 1: Is there a way to perform the sort based upon the content of a column without having to transpose the array first.
Question 2: Row 0 (array elements A$(0,0) up to A$(0,4) can contain irrelevant data. How to avoid that this row is also taken into the sort. I'm not sure if I need to use the line C% = DIM(B$(),DIM(B$()))+1 or just C% = DIM(B$(),DIM(B$())) or another approach.
Thanks for any feedback,
Eddy
MODE 28 INSTALL @lib$+"SORTLIB" INSTALL @lib$+"ARRAYLIB" DIM A$(8,4),B$(4,8) FOR r=1 TO 8:FOR c=1 TO 4:READ A$(r,c):NEXT c:NEXT r PROC_Show_A$ PROC_transpose$(A$(), B$()) PROC_Show_B$ sort% = FN_sortinit(0,2) C% = DIM(B$(),DIM(B$()))+1 CALL sort%, B$(3,0),B$(1,0),B$(2,0),B$(4,0) PROC_Show_B$ PROC_transpose$(B$(),A$()) PROC_Show_A$ END REM ---------------------------------------------------------------- DEF PROC_Show_A$ FOR r=1 TO 8:PRINT SPC2 A$(r,1) TAB(32) A$(r,2) TAB(40) A$(r,3) TAB(55) A$(r,4):NEXT r PRINT STRING$(120,"_") ENDPROC REM ---------------------------------------------------------------- DEF PROC_Show_B$ FOR r=1 TO 4:FOR c=1 TO 7:PRINT B$(r,c) SPC5;:NEXT c:PRINT B$(r,c),:NEXT r PRINT STRING$(120,"_") ENDPROC REM ---------------------------------------------------------------- DATA Gaztransport,177,IE003262,BRU,GLAXOSMITHKLINE,306,LU020157,NAV,GRANDVISION,199,AU031893 DATA OTC,MYTHRA,103,LU017361,NAV,SISF UK OPP AD,66,ZS464286,BRU,TH UK EQ GBP,231,US500631 DATA LSE,UMICORE,12114,FR001040,AEX,VODAFONE,196,LU010939,LSE,BOMBARDIER,1900,KL100584,PSE