Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: ArraySort Sort Order Negative Positive Word Integer Floating Point Vartype Intuitive Sort Explained
Here is my data:
-00.14 07/04/12 91.64 1 91.64 92.20 +00.84 07/04/12 54.04 1 54.04 54.08 +02.21 07/04/12 49.53 1 49.53 49.83 +00.22 07/04/12 44.65 1 44.65 44.79 -01.92 07/04/12 44.29 1 44.29 44.35 +00.95 07/04/12 30.89 1 30.89 31.07 +01.10 07/04/12 23.84 1 23.84 24.03 +00.11 07/04/12 18.52 1 18.52 18.61 +02.35 07/04/12 06.54 1 06.54 06.55Here is my script:
File_PortPreSort = "c:\temp\Portfolio_PreSort.txt" File_PortSort = "c:\temp\Portfolio_Sort.txt" filedelete(File_PortSort) filarray_PreSort=ArrayFileGet(File_PortPreSort) ArraySort( filarray_PreSort, @DESCENDING, 0, 0, ArrInfo(filarray_PreSort,1)-1 ) ArrayFilePut( File_PortSort, filarray_PreSort ) Run( File_PortSort, '' )
; Example for ambiguous sorting. ; Set file names. DirChange (DirScript ()) strFileIn = "Portfolio_PreSort.txt" strFileOut1 = "Portfolio_Sort.1.txt" strFileOut2 = "Portfolio_Sort.2.txt" strFileOut3 = "Portfolio_Sort.3.txt" ; For sure delete existing output files. FileDelete (strFileOut1) FileDelete (strFileOut2) FileDelete (strFileOut3) ; Read data into dim-1 array and sort descending. arrData = ArrayFileGet (strFileIn) intVarType = VarType (arrData[0]) ; 2 = String. ArraySort (arrData, @DESCENDING) ArrayFilePut (strFileOut1, arrData) ; Read data into dim-2 array and sort descending on col-0. arrData = ArrayFileGetCSV (strFileIn, 0, @TAB) intVarType = VarType (arrData[0, 0]) ; 2 = string. ArraySort (arrData, @DESCENDING, 0) ArrayFilePutCSV (strFileOut2, arrData, @TAB, @TRUE, 2) ; Read data into dim-2 array, convert col-0 datatype to float and sort descending on col-0. arrData = ArrayFileGetCSV (strFileIn, 0, @TAB) intLast = ArrInfo (arrData, 1) - 1 For intI = 0 To intLast intVarType = VarType (arrData[intI, 0]) ; 2 = string. If IsFloat (arrData[intI, 0]) Then arrData[intI, 0] = 1.0 * arrData[intI, 0] intVarType = VarType (arrData[intI, 0]) ; 32 = floating point value. Next ArraySort (arrData, @DESCENDING, 0) ArrayFilePutCSV (strFileOut3, arrData, @TAB, @TRUE, 2) ; Display results. Run (strFileOut1, "") Run (strFileOut2, "") Run (strFileOut3, "") :CANCEL Exit
Article ID: W17677
Filename: ArraySort Intuitive Sort Explained.txt
File Created: 2012:07:05:09:14:32
Last Updated: 2012:07:05:09:14:32