Fire Posted December 19, 2009 Share Posted December 19, 2009 Hi to all.Have small question about arrays.Say i have array:#include <Array.au3> Local $avArray[10] $avArray[0] = "12" $avArray[1] = "2" $avArray[2] = "3" $avArray[3] = "0" $avArray[4] = "5" $avArray[5] = "6" $avArray[6] = "150" $avArray[7] = "8" $avArray[8] = "9" $avArray[9] = "7" MsgBox(64, "",_ArrayMin($avArray,1,0,0)) MsgBox(64, "",_ArrayMax($avArray,1,0,9))In result i want sort its like:0,2,3,5,6,7,8,9,12,150also i try _ArraySort,and searched about this in forum and i find:http://www.autoitscript.com/forum/index.php?showtopic=94799&st=0&p=703473&hl=compare%20arrays&fromsearch=1&#entry703473But unable to do like above.Any tips appreciated.P.S I know i will try it under loop like:for example:for $i=3 to 10 MsgBox(64, "",_ArrayMin($avArray,1,$i,0)) If $i=10 Then ExitLoop EndIf Next ExitBut in here too i cannot figure it out correctly.Yet i try this too like:#include <Array.au3> Local $avArray = StringSplit("4,2,0", ",") MsgBox(64,"Min 1 n","Fist min ==> " & _ArrayMin($avArray, 1,1, 0)) MsgBox(64,"Min 2 ","Second min => " & " " & _ArrayMin($avArray,1,1, 2)) MsgBox(64, "Maks","Max => " & _ArrayMax($avArray,1,1,0)) exitBut what if the the numders here over 10k?How to compare it automatically and sort of alllike below:0,2,3,5,6,7,8,9,12,150 and etc.I need really your tips about this.Thanks again to all. [size="5"] [/size] Link to comment Share on other sites More sharing options...
Developers Jos Posted December 19, 2009 Developers Share Posted December 19, 2009 Looks like you are sorting strings, not numbers! Convert the strings to numbers before sorting. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 19, 2009 Moderators Share Posted December 19, 2009 Sh3llC043r,You need to decide whether you want to sort number or strings. Go and look at the $iCompNumeric parameter for _ArrayMax and _ArrayMin - that might help. 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...
Fire Posted December 19, 2009 Author Share Posted December 19, 2009 I`m sorry again for stupid question but i`m trying to receive result which i want but no success again Already I tear hair as I can not receive correct result. I will forgive from you tell where my errors in this case:(Plizz i just need one simple and i think this is enough for me for handle correctly it in future) #include <Array.au3> Local $avArray[3] $avArray[0] = "12" $avArray[1] = "0" $avArray[2]="2" ;MsgBox(64, "dd",UBound($avArray,1)) ;3 dimension this is right. for $i =1 To UBound($avArray,1) ;3 MsgBox(64, "",_ArrayMin($avArray,1,$i,UBound($avArray,1))) MsgBox(64, "",_ArrayMax($avArray,1,$i,0)) if $i=3 Then ExitLoop Else EndIf Next [size="5"] [/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 20, 2009 Moderators Share Posted December 20, 2009 Sh3llC043r, Where did the loop come from? All you need is: #include <Array.au3> Local $avArray[3] $avArray[0] = "12" ; These are strings $avArray[1] = "0" $avArray[2] = "2" ; So we need to tell the function to compare as numbers by setting the $iCompNumeric parameter to 1 MsgBox(64, "Min Number", _ArrayMin($avArray, 1)) MsgBox(64, "Max Number", _ArrayMax($avArray, 1)) ; Compare the results here where we compare as strings MsgBox(64, "Min String", _ArrayMin($avArray)) MsgBox(64, "Max String", _ArrayMax($avArray)) I hope that is clear. 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...
Fire Posted December 20, 2009 Author Share Posted December 20, 2009 Hi,Dear Melba23. Thank you very much for your help again.But here is my simple script and i have logical wrong programm.#include <GUIConstants.au3> #include <Array.au3> $Form1 = GUICreate("", 205, 322, 283, 156) $Input1 = GUICtrlCreateInput("", 48, 64, 113, 21) $Input2 = GUICtrlCreateInput("", 48, 128, 113, 21) $Input3 = GUICtrlCreateInput("", 48, 192, 113, 21) $Button1 = GUICtrlCreateButton("OK", 64, 256, 81, 25, 0) $Label1 = GUICtrlCreateLabel(" ENTER DIGITS", 16, 8, 122, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Local $avArray[3] $avArray[0] =GUICtrlRead($Input1) $avArray[1] = GUICtrlRead($Input2) $avArray[2] =GUICtrlRead($Input3) MsgBox(64, "Min Number", _ArrayMin($avArray, 1)) MsgBox(64, "Min Number 1", _ArrayMin($avArray, 1,2,2)) MsgBox(64, "Max Number",_ArrayMax($avArray,1)) EndSwitch WEndFor example:Say i enter :----------------------------------------- | INPUTBOX1 | 1 | ----------------------------------------- | INPUTBOX2 | 152 | ----------------------------------------- | NPUTBOX3 | 3 | -----------------------------------------Result in this case is correct for me.__________________________________________________________________________But when i enter:----------------------------------------- | INPUTBOX1 | 5000 | ----------------------------------------- | INPUTBOX2 | 0 | ----------------------------------------- | INPUTBOX3 | 9000000 | -----------------------------------------result is this case is logical wrong 66% .I want to know how to prevent it and get logical correct result(100%) in this case? or write right code?I know 100% in my this code arrays used by static logical prinsipe.( there must be some dynamic "handle" method(s) for array index)But how to do this correct logical in dynamyc prinsipe?some tips,hints will be appreciated.Thank you very-very much again. [size="5"] [/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 20, 2009 Moderators Share Posted December 20, 2009 Sh3llC043r,Your code is doing exactly what you have asked it to do:First MsgBox - shows the lowest number in the array. Using your examples I get: 1 & 0 - which is what I would expect.Third MsgBox - shows the highest number in the array. Your examples give: 152 & 9000000 - again what I would expect.But the syntax of the Second MsgBox only looks at the contents of element [2] of the array - so it will only ever return the value of that element - which it does: 3 & 9000000.What do you want this second MsgBox to display? As to the "dynamic" arrays, take a look at this:#include <GUIConstantsEx.au3> #include <Array.au3> Global $avArray[3], $Input[UBound($avArray)] $Form1 = GUICreate("", 205, 322, 283, 156) $Input[0] = GUICtrlCreateInput("", 48, 64, 113, 21) $Input[1] = GUICtrlCreateInput("", 48, 128, 113, 21) $Input[2] = GUICtrlCreateInput("", 48, 192, 113, 21) $Button1 = GUICtrlCreateButton("OK", 64, 256, 81, 25, 0) $Label1 = GUICtrlCreateLabel(" ENTER DIGITS", 16, 8, 122, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 For $i = 0 To UBound($avArray) - 1 ConsoleWrite($i & " - " & $Input[$i] & @CRLF) $avArray[$i] = GUICtrlRead($Input[$i]) Next MsgBox(64, "Min Number in Array", _ArrayMin($avArray, 1)) ; What does this next MsgBox do? ; You are only looking at the [2] element so you will only ever get the number in $Input[2]! MsgBox(64, "Min Number 1", _ArrayMin($avArray, 1, 2, 2)) MsgBox(64, "Max Number in Array", _ArrayMax($avArray, 1)) EndSwitch WEndM23 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...
Fire Posted December 20, 2009 Author Share Posted December 20, 2009 (edited) I agree with you Melba23. I have changed the second msgbox and it will be display to me:1`st index of array. Case $Button1 Local $avArray[3] $avArray[0] =GUICtrlRead($Input1) $avArray[1] = GUICtrlRead($Input2) $avArray[2] =GUICtrlRead($Input3) MsgBox(64, "Min Number", _ArrayMin($avArray, 1)) MsgBox(64, "Min Number 1", _ArrayMin($avArray, 1)) MsgBox(64, "Max Number",_ArrayMax($avArray,1)) What do you want this second MsgBox to display?Ok lets say: inputbox1 5000 inputbox2 0 inputbox3 9000000 and now i push OK button. Fisrt msgbox appear and it is show me min value in this case it is 0. Second msgbox appear after this and it is show me another min value in this case it is 0 too. And the third msgbox appear it is show me 900000. But where 5000 which i enter? The 5000 in general is not present in result:( But my target is get result like below(from low to hi): 0 on first msgbox. 5000 on second msgbox. 900000 on third msgbox. What i`m doing somethink wrong in this? P.S i change MsgBox(64, "Min Number 1", _ArrayMin($avArray, 1)) but i`m unable get result which i want to do. Thank you again Melba23 for take your gold time for me. Edited December 20, 2009 by Sh3llC043r [size="5"] [/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 20, 2009 Moderators Share Posted December 20, 2009 Sh3llC043r,You need to sort the array itself - _ArrayMin and _ArrayMax will, as their names suggest, only get you the minimum and maximum values.This should be what you need:#include <GUIConstantsEx.au3> #include <Array.au3> Global $avArray[3], $Input[UBound($avArray)] $Form1 = GUICreate("", 205, 322, 283, 156) $Input[0] = GUICtrlCreateInput("", 48, 64, 113, 21) $Input[1] = GUICtrlCreateInput("", 48, 128, 113, 21) $Input[2] = GUICtrlCreateInput("", 48, 192, 113, 21) $Button1 = GUICtrlCreateButton("OK", 64, 256, 81, 25, 0) $Label1 = GUICtrlCreateLabel(" ENTER DIGITS", 16, 8, 122, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 For $i = 0 To UBound($avArray) - 1 $avArray[$i] = Number(GUICtrlRead($Input[$i])) Next _ArraySort($avArray) For $i = 0 To UBound($avArray) - 1 MsgBox(64, "$i", $avArray[$i]) Next EndSwitch WEnd 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...
Fire Posted December 20, 2009 Author Share Posted December 20, 2009 Yes.Thank youuuu. I will learn from it.Thank you again Melba23 [size="5"] [/size] 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