nitekram Posted August 29, 2010 Share Posted August 29, 2010 My problem is that I need to know which is the smalles number and then cont. to the largest number. What is happening is that the numbers are going by the digit and I need it to go to the whole number...does anyone know what I am doing wrong? expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> Local $data[20][2], $data2[20] Local $strintest = 0, $setit $gui = GUICreate('', 260, 410) $test = GUICtrlCreateCombo('', 0, 0, 200, 350, $WS_VSCROLL) GUICtrlSetFont(-1, 10, Default, Default, "Consolas") $but0 = GUICtrlCreateButton('col1', 200, 50) $but1 = GUICtrlCreateButton('col2', 200, 150) GUISetState() For $i = 0 To UBound($data) - 1 For $j = 0 To Random(3, 10) $data[$i][0] &= Random('1', '7', 1) $data[$i][1] &= Random('1', '7', 1) Next Next For $g = 0 To UBound($data) - 1 If $strintest <= StringLen($data[$g][0]) Then $strintest = StringLen($data[$g][0]) Next $strintest += 5 For $l = 0 To UBound($data) - 1 If StringLen($data[$l][0]) <> $strintest Then Do $data[$l][0] &= ' ' Until StringLen($data[$l][0]) >= $strintest EndIf Next _ArraySort($data, 0, 0, 0, 1) For $i = 0 To UBound($data) - 1 ConsoleWrite('!>' & $data[$i][0] & $data[$i][1] & @CRLF) $setit &= $data[$i][0] & $data[$i][1] & '|' Next GUICtrlSetData($test, $setit) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $but0 Then ;MsgBox('','','') _ArraySort($data, 0, 0, 0, 0) $setit = '' For $i = 0 To UBound($data) - 1 ConsoleWrite('!>' & $data[$i][0] & $data[$i][1] & @CRLF) If $data[$i][0] <> 0 Then $setit &= $data[$i][0] & $data[$i][1] & '|' Next GUICtrlSetData($test, '') GUICtrlSetData($test, $setit) EndIf If $msg = $but1 Then ;MsgBox('','','') $setit = '' _ArraySort($data, 0, 0, 0, 1) For $i = 0 To UBound($data) - 1 ConsoleWrite('!>' & $data[$i][0] & $data[$i][1] & @CRLF) $setit &= $data[$i][0] & $data[$i][1] & '|' Next GUICtrlSetData($test, '') GUICtrlSetData($test, $setit) EndIf WEnd 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 29, 2010 Share Posted August 29, 2010 Look at the code for _ArraySort and you will notice something, if it finds a number it do a numerical comparison, otherwise it's just a string comparison. And what do you have? For $i = 0 To UBound($data) - 1 ConsoleWrite('!>' & $data[$i][0] & "/" & VarGetType($data[$i][0]) & @TAB & $data[$i][1] & @TAB & "/" & VarGetType($data[$i][1]) & @CRLF) $setit &= $data[$i][0] & $data[$i][1] & '|' Next Only strings... Good planning there! .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
czardas Posted August 29, 2010 Share Posted August 29, 2010 Perhaps this is not entirely relevant here, but I thought it might be worth a mention. Sometimes I concatonate strings and numbers for various reasons (mainly to create numerical tags). Often when I do this, I prefix zeros to the numbers prior to concatonation, to avoid this kind of ambiguity. Maybe there are better ways to do this - I'm not sure. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 29, 2010 Share Posted August 29, 2010 @czardasNot sure what you mean.The problem here is that nitekram is abusing that List-control by putting a bunch of spaces in the array. Numbers don't have spaces. Right?@nitekramHere's a situation where you should just let your imagination go free and you will quickly find a solution.Three examples and my thought on them:Move the spaces to a second array (errr no)Generate the spaces when the list is to be filled (why waste cpu on that?)Use a ListView and a Input instead (awesome!) .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 29, 2010 Moderators Share Posted August 29, 2010 nitekram,Or just add another element to your array to hold the spaces and make sure the numerical values are stored as Numbers. Look between the <<<<<<< lines. There are a few changes to some other lines as well, but they shoud be pretty obvious :expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> Local $data[20][3], $data2[20] Local $strintest = 0, $setit $gui = GUICreate('', 260, 410) $test = GUICtrlCreateCombo('', 0, 0, 200, 350, $WS_VSCROLL) GUICtrlSetFont(-1, 10, Default, Default, "Consolas") $but0 = GUICtrlCreateButton('col1', 200, 50) $but1 = GUICtrlCreateButton('col2', 200, 150) GUISetState() For $i = 0 To UBound($data) - 1 For $j = 0 To Random(3, 10) $data[$i][0] &= Random('1', '7', 1) $data[$i][2] &= Random('1', '7', 1) Next Next ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< For $i = 0 To UBound($data) - 1 $n = 9 - StringLen($data[$i][0]) $data[$i][1] = " " For $j = 0 To $n $data[$i][1] &= " " Next $data[$i][0] = Number($data[$i][0]) $data[$i][2] = Number($data[$i][2]) Next ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< _ArraySort($data, 0, 0, 0, 1) For $i = 0 To UBound($data) - 1 ConsoleWrite('!>' & $data[$i][0] & $data[$i][1] & $data[$i][2] & @CRLF) $setit &= $data[$i][0] & $data[$i][1] & $data[$i][2] & '|' Next GUICtrlSetData($test, $setit) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $but0 Then ;MsgBox('','','') _ArraySort($data, 0, 0, 0, 0) $setit = '' For $i = 0 To UBound($data) - 1 ConsoleWrite('!>' & $data[$i][0] & $data[$i][1] & $data[$i][2] & @CRLF) If $data[$i][0] <> 0 Then $setit &= $data[$i][0] & $data[$i][1] & $data[$i][2] & '|' Next GUICtrlSetData($test, '') GUICtrlSetData($test, $setit) EndIf If $msg = $but1 Then ;MsgBox('','','') $setit = '' _ArraySort($data, 0, 0, 0, 2) For $i = 0 To UBound($data) - 1 ConsoleWrite('!>' & $data[$i][0] & $data[$i][1] & $data[$i][2] & @CRLF) $setit &= $data[$i][0] & $data[$i][1] & $data[$i][2] & '|' Next GUICtrlSetData($test, '') GUICtrlSetData($test, $setit) EndIf WEndHappy? 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...
czardas Posted August 29, 2010 Share Posted August 29, 2010 (edited) Numbers don't have spaces. Right?Right!Not sure what you mean.Suppose I find two identical strings in an array search. I may wish to log them separately: string001 and string018. While it normally has no significance where the strings were found, in one instance I needed to sort the strings in a completely controlled manner. So I added tags to ensure predictable behaviour. The reason had to do with the nature of the rest of the code. I hope that makes a little bit more sense. So the sorted strings would end up being sorted first by alphabet, and then by the order in which they appeared: This had the additional bonus that the process could also be reversed. Perhaps that might seem strange, but it was just what I needed at the time. Edited August 29, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
nitekram Posted August 30, 2010 Author Share Posted August 30, 2010 Thanks for your help...again! 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator 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