andybiochem Posted September 5, 2008 Share Posted September 5, 2008 Hi,Just thought I'd share this - I use it quite a lot, thought it might be useful to someone.....nothing special really.What it does:Say you had an array of data looking like this:12,123,3323,43,12345,55,3233,443,474,46,8899,102,9....and you wanted to sort it low to high by reference to the 3rd item, to look like this:3,443,499,102,912,123,3374,46,8823,43,12345,55,323 You can use this UDF to do that.UDF:; #FUNCTION# ============================================================================ ; Name...........: _ArraySort_ByDelimitedItem ; Description ...: Sorts delimited data by item reference ; Syntax.........: _ArraySort_ByDelimitedItem(ByRef $aArray,$cDelimiter,$iItem,$iDescending = 0) ; Parameters ....: $aArray - Array of delimited data to sort ; $cDelimiter - delimiter character ; $iItem - data item to sort by ; $iDescending - 0=low to high, 1=high to low ; Notes..........: Requires <Array.au3> ; ======================================================================================= Func _ArraySort_ByDelimitedItem(ByRef $aArray,$cDelimiter,$iItem,$iDescending = 0) Local $aItems[UBound($aArray)][2] For $i = 1 To (UBound($aItems) - 1) $aItems[$i][0] = $aArray[$i] $aData = StringSplit($aArray[$i],$cDelimiter) $aItems[$i][1] = Number($aData[$iItem]) Next _ArraySort($aItems,$iDescending,1,UBound($aItems) - 1,1) For $i = 1 to (UBound($aArray) - 1) $aArray[$i] = $aItems[$i][0] Next EndFuncExample useage:expandcollapse popup#include <Array.au3> ;----- create some random data to sort ----- Dim $Data[101] For $i = 1 to 100 $Data[$i] = Random(0,100,1) & "," & Random(0,100,1) & "," & Random(0,100,1) Next _ArrayDisplay($Data,"Data NOT sorted") _ArraySort_ByDelimitedItem($Data,",",3,0) _ArrayDisplay($Data,"Data sorted by 3rd item") ; #FUNCTION# ============================================================================ ; Name...........: _ArraySort_ByDelimitedItem ; Description ...: Sorts delimited data by item reference ; Syntax.........: _ArraySort_ByDelimitedItem(ByRef $aArray,$cDelimiter,$iItem,$iDescending = 0) ; Parameters ....: $aArray - Array of delimited data to sort ; $cDelimiter - delimiter character ; $iItem - data item to sort by ; $iDescending - 0=low to high, 1=high to low ; Notes..........: Requires <Array.au3> ; ======================================================================================= Func _ArraySort_ByDelimitedItem(ByRef $aArray,$cDelimiter,$iItem,$iDescending = 0) Local $aItems[UBound($aArray)][2] For $i = 1 To (UBound($aItems) - 1) $aItems[$i][0] = $aArray[$i] $aData = StringSplit($aArray[$i],$cDelimiter) $aItems[$i][1] = Number($aData[$iItem]) Next _ArraySort($aItems,$iDescending,1,UBound($aItems) - 1,1) For $i = 1 to (UBound($aArray) - 1) $aArray[$i] = $aItems[$i][0] Next EndFuncLike I said, nothing much really, just makes sorting CSVs and the like a bit easier.Ta! - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now