error471 Posted February 4, 2016 Share Posted February 4, 2016 Hey folks, I have a quite simple but weird problem with _ArraySort. Check it out: #include <Array.au3> Local $avArray[5][2] = [ _ [15, 20], _ ['24', 32], _ [8, 16], _ [3, 35], _ ['10,5', 19]] _ArrayDisplay($avArray, "$avArray BEFORE _ArraySort()") _ArraySort($avArray, 1, 0, 0, 0) _ArrayDisplay($avArray, "$avArray AFTER _ArraySort() ascending column 0") The leftmost column should be sorted descending. But the strings make some problems. Does someone have a quick solution? Best Wishes error471 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2016 Moderators Share Posted February 4, 2016 (edited) error471, Force all the elements into the Number datatype before sorting: #include <Array.au3> Local $avArray[5][2] = [ _ [15, 20], _ ['24', 32], _ [8, 16], _ [3, 35], _ ['10,5', 19]] _ArrayDisplay($avArray, "$avArray BEFORE _ArraySort()") For $i = 0 To UBound($avArray) - 1 $avArray[$i][0] = Number($avArray[$i][0]) Next _ArraySort($avArray, 1, 0, 0, 0) _ArrayDisplay($avArray, "$avArray AFTER _ArraySort() ascending column 0") By default _ArraySort sorts on character ASCII codes, hence the apparent errors. M23 Edited February 4, 2016 by Melba23 Typo error471 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
spudw2k Posted February 4, 2016 Share Posted February 4, 2016 (edited) It looks like it's working as expected to me. Since '24' is wrapped in quotes (as is '10,5') it is interpreted as a string. I can understand that not showing the quotes in the arraydisplay output is confusing, but it is bahaving as expected based on the datatypes (ASCII codes...thanks Melba)--notice the numbers sorted and grouped as are the strings. edit: I was going to suggest what Melba has, except I would've enforced the "number" datatype during array population. It's probably more important to make sure the datatype is accurate when the script needs to "act' on the data versus when the data is produced. Garbage in, garbage out. Edited February 4, 2016 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
error471 Posted February 4, 2016 Author Share Posted February 4, 2016 Thank you Melba23. It worked. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2016 Moderators Share Posted February 4, 2016 spudw2k, 5 minutes ago, spudw2k said: Garbage in, garbage out I used to know the guy who coined that expression - the much-missed Wilf Hey. His "Wilf's Worshop" series in the PCPlus magazine was required reading when I was younger. I even won a prize in one of his weekly competitions - this particular one was to code for Turing machine. My prize was "FromBat", a tool which produced executables from essentially DOS batch file code with a lot of added functions - a sort of proto-DOS-based- Autoit I suppose. Happy days...... M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2016 Moderators Share Posted February 4, 2016 error471, My pleasure, as always. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
error471 Posted February 4, 2016 Author Share Posted February 4, 2016 @Melba23: The problem now is, that the decimal values are integers now. That is impractical for the output... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2016 Moderators Share Posted February 4, 2016 (edited) error471, That is because you are using the continental comma ( , ) to indicate a decimal and not the expected period ( . ). I always thought that Windows and AutoIt used the settings for the local machine, so perhaps you have not set this correctly. If this is not the case then you will need to convert the separator at the same time as converting the datatype: $avArray[$i][0] = Number(StringReplace($avArray[$i][0], ", ", ".")) Anyway, I thought this was for a bakery - how come you deal in decimals? M23 Edited February 4, 2016 by Melba23 Typo Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
error471 Posted February 4, 2016 Author Share Posted February 4, 2016 I understand. That comma/period changing will cause a lot of unnecessary code... It is for a bakery, but it should be easy to adapt for other thinkable practice right from the beginning. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2016 Moderators Share Posted February 4, 2016 (edited) error471, Quote That comma/period changing will cause a lot of unnecessary code Not necessarily. As you use my UDF, you can use the array returned by _GUIListViewEx_EditOnClick to remove the commas as they are entered. Give me a moment to work up an example. M23 Edit: Here you are: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx_Mod.au3" $hGUI = GUICreate("Test", 500, 500) ; Create ListView $cLV_1 = GUICtrlCreateListView("Zero Column|One Column|Two Column|Three Column", 10, 10, 480, 280, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS)) _GUICtrlListView_SetExtendedListViewStyle($cLV_1, $LVS_EX_FULLROWSELECT) For $i = 0 To 0 _GUICtrlListView_SetColumnWidth($cLV_1, $i, 100) Next ; Create array and fill listview Global $aLVArray_1[6][4] For $i = 0 To 5 $sData = "Item " & $i & "-0" $aLVArray_1[$i][0] = $sData For $j = 1 To 3 $sData &= "|SubItem " & $i & "-" & $j $aLVArray_1[$i][$j] = "SubItem " & $i & "-" & $j Next GUICtrlCreateListViewItem($sData, $cLV_1) Next ; Initiate ListView - edit on click all columns $iLVIndex_1 = _GUIListViewEx_Init($cLV_1, $aLVArray_1, 0, 0, True, 2) _GUIListViewEx_MsgRegister() GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit EndSwitch ; Allow edit on double click $aRet = _GUIListViewEx_EditOnClick() If IsArray($aRet) Then ; Loop through the changes For $i = 1 to $aRet[0][0] ; Look for commas If StringinStr($aRet[$i][3], ",") Then ; replace with decimal points $sReplace = Number(StringReplace($aRet[$i][3], ",", ".")) ; programatically set the content _GUIListViewEx_ChangeItem($iLVIndex_1, $aRet[$i][0], $aRet[$i][1], $sReplace) EndIf Next EndIf WEnd Not too difficult. Edited February 4, 2016 by Melba23 Added Number forcing too Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted February 4, 2016 Share Posted February 4, 2016 error471, Why is some of the data strings and other data numbers (some of which are "real")? At some point it might benefit you to share your code and/or design concepts... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
error471 Posted February 4, 2016 Author Share Posted February 4, 2016 @kylomas: That is a good question. I work with Melba23s GUIListViewEx, which probably saves some input as string, and some as number. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2016 Moderators Share Posted February 4, 2016 error471, My UDF saves all edited items as strings. You are running into one of the "features" of AutoIt - variables are not typed and so can be either strings or numbers. Normally this makes for easy coding, but can bite you if you are not careful. It was a design decision by Jon when he first started - personally I think it was correct, even if it catches experienced coders out from time to time (speaking from experience here)! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
error471 Posted February 4, 2016 Author Share Posted February 4, 2016 It makes programming definetely easier how it is actually. I am not complaining. I will handle it... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2016 Moderators Share Posted February 4, 2016 (edited) error471, Did you see my example code above? Using something like that makes it really easy to get the input in a suitable format immediately - you could even force the Number datatype at that point as well as I have now done. M23 Edited February 4, 2016 by Melba23 Amended earlier code Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
error471 Posted February 4, 2016 Author Share Posted February 4, 2016 Yes, your exampe is a good solution. 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