JAFN Posted April 12, 2011 Share Posted April 12, 2011 The code below creates an updown just fine. But it will only up not down. Any ideas? Let me know if you need more of the code. Thanks. $GUIid = GUICreate($NameVersion, $WinWidth, 100, $WinX, $WinY) GUICtrlCreateLabel("Minutes", 10, $SepY, 180, $SepY - 4) $Timer = GUICtrlCreateInput($inputStart, 70, $SepY - 10, 50, $SepY) $updown = GUICtrlCreateUpdown($Timer) GUICtrlSetLimit($updown, 250, 1) [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 12, 2011 Moderators Share Posted April 12, 2011 JAFN,Your label overlaps the "down" arrow - overlapping controls means that neither work as AutoIt cannot tell which you meant to action. Top Tip: If ever controls do not work for no reason add some colour to the labels and check for overlapping. GUICtrlCreateLabel("Minutes", 10, $SepY, 180, $SepY - 4) GUICtrlSetBkColor(-1, 0xFF0000) $Timer = GUICtrlCreateInput($inputStart, 70, $SepY - 10, 50, $SepY) $updown = GUICtrlCreateUpdown($Timer) GUICtrlSetLimit($updown, 250, 1)And the problem is obvious! 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...
JAFN Posted April 12, 2011 Author Share Posted April 12, 2011 I've had 'a ha' moments with every other problem I have created for myself in this program. I will stare at it some more. At least I know the problem is here. Thanks. [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 12, 2011 Moderators Share Posted April 12, 2011 JAFN,I will stare at it some more. At least I know the problem is here.I explained what the problem was - did you not understand? 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...
JAFN Posted April 12, 2011 Author Share Posted April 12, 2011 I did as you said and it works now. And just as I wrote the line above the light dinged and I understood why. A whole nother thing thing to be careful of. Thank you. One other question while I've got you here: If I click on the exit in the tray menu nothing I've tried to date has made it so that the gui would close. Any pointers? [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 12, 2011 Moderators Share Posted April 12, 2011 JAFN, Glad you got it. As for the tray menu, I need some code - my crystal ball is at the cleaners! 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...
JAFN Posted April 12, 2011 Author Share Posted April 12, 2011 Can't figure what to send so I'm sending all of my very simple program.. I have previously removed the non-working code for exiting. Please forgive what I am sure is horrible coding, a lot of it was learning so there is much that is not needed. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=shout.ico #AutoIt3Wrapper_Outfile=iteration.exe #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstants.au3> #include <GUIConstantsEx.au3> FileInstall("shout.ico", "shout.ico", 0) $NameVersion = "iTeration 1.04" Global $GUIid = "" #NoTrayIcon Opt("TrayMenuMode", 3) ; Default tray menu items (Script Paused/Exit) will not be shown. Opt("TrayOnEventMode", 1) ; Enable Tray Events Opt("TrayAutoPause", 0) ; No Pause on Menu ; Create Tray Menu ; Set Events for Tray Menu $iTerationItem = TrayCreateItem("Go") TrayItemSetOnEvent($iTerationItem, "StartMain") TrayCreateItem("") ; seperation line $aboutItem = TrayCreateItem("About") TrayItemSetOnEvent($aboutItem, "aboutMsg") TrayCreateItem("") ; seperation line $exitItem = TrayCreateItem("Exit") TrayItemSetOnEvent($exitItem, "MyExit") TraySetState() Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE MyExit() Func MyExit() Local $WPos[4] $WPos = WinGetPos($GUIid) IniWrite("iTeration.ini", "Starting Value", "Window Left", $WPos[0]) IniWrite("iTeration.ini", "Starting Value", "Window Top", $WPos[1]) Exit EndFunc ;==>MyExit Func aboutMsg() Local $message $message = $NameVersion & @CRLF & @CRLF $message = $message & "by Garth Bigelow" $message = $message & @CRLF & "With the infinite patience of the AutoIt Help Forums" & @CRLF $message = $message & @CRLF & "no rights reserved" MsgBox(64, "about:", $message) EndFunc ;==>aboutMsg Func StartMain() $WinWidth = 280 ;$WinX = @DesktopWidth - $WinWidth - 2 $SepY = 30 $ButWidth = 100 ; 80 $inputStart = IniRead("iTeration.ini", "Starting Value", "Input", "17") $WinX = IniRead("iTeration.ini", "Starting Value", "Window Left", @DesktopWidth - $WinWidth - 2) $WinY = IniRead("iTeration.ini", "Starting Value", "Window Top", $SepY) $GUIid = GUICreate($NameVersion, $WinWidth, 100, $WinX, $WinY) GUICtrlCreateLabel("Minutes", 10, $SepY, 48, $SepY - 4) ;GUICtrlSetBkColor(-1, 0xFF0000) $Timer = GUICtrlCreateInput($inputStart, 70, $SepY - 10, 50, $SepY) $updown = GUICtrlCreateUpdown($Timer) GUICtrlSetLimit($updown, 250, 1) $Display = GUICtrlCreateInput(" ", 70, $SepY + 30, 50, $SepY - 10) GUICtrlSetState($Display, $GUI_DISABLE) ;GUICtrlSetColor($Display, 0x00ffff) $Start = GUICtrlCreateButton("Start", ($WinWidth - $ButWidth - 10), $SepY - 18, $ButWidth, $SepY) $Stop = GUICtrlCreateButton("Stop", ($WinWidth - $ButWidth - 10), $SepY + 40 - 18, $ButWidth, $SepY) GUICtrlSetState($Stop, $GUI_DISABLE) GUISetState() OnAutoItExitRegister("MyExit") $begin = 0 $click = 0 $EndVar = 0 $NowVar = -1 Do $msg = GUIGetMsg() If $NowVar >= $EndVar Then $msg = $Stop Beep(1000, 200) Beep(400, 400) EndIf If $msg = $Stop Then $begin = 0 GUICtrlSetState($Timer, $GUI_ENABLE) GUICtrlSetState($Start, $GUI_ENABLE) GUICtrlSetState($Stop, $GUI_DISABLE) ; WinSetOnTop ( $GUIid, "", 0) $NowVar = -1 EndIf If $msg = $Start Then GUICtrlSetState($Timer, $GUI_DISABLE) GUICtrlSetState($Start, $GUI_DISABLE) GUICtrlSetState($Stop, $GUI_ENABLE) ; GUICtrlSetData ($Display, $ms) $begin = TimerInit() $EndVar = MinutesToMillseconds(GUICtrlRead($Timer)) $click = 0 WinSetOnTop($GUIid, "", 1) IniWrite("iTeration.ini", "Starting Value", "Input", GUICtrlRead($Timer)) EndIf If $begin <> 0 Then $NowVar = TimerDiff($begin) $DispVar = MillsecondsToMinutes($NowVar) If $DispVar > Floor($click) Then $dummy = StringFormat("%3u", Ceiling(GUICtrlRead($Timer) - $DispVar)) ; ("%%.2f = '%.2f'\n", $ms) GUICtrlSetData($Display, $dummy) $click = Floor($DispVar) EndIf EndIf Until $msg = $GUI_EVENT_CLOSE IniWrite("iTeration.ini", "Starting Value", "Input", GUICtrlRead($Timer)) MyExit() EndFunc Func MillsecondsToMinutes($milli) $minutes = $milli / 60000 Return $minutes EndFunc ;==>MillsecondsToMinutes Func MinutesToMillseconds($milli) $minutes = $milli * 60000 Return $minutes EndFunc ;==>MinutesToMillseconds [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2011 Moderators Share Posted April 13, 2011 JAFN,First, a short explanation of why it did not work. AutoIt queues events and deals with them in order. Function calls initiated by events are (in nearly all cases) actioned once AutoIt has returned to the idle loop (that is the GUIGetMsg or Sleep loop that keeps the script alive) - if you are within a function you cannot interrupt it to start another one via an event. So in your case you were remaining in the idle loop within the StartMain function and the MyExit function called by the tray Event was waiting patiently in the queue.The exceptions to this queuing limitation are HotKeys - they will interrupt running functions. There are also tricks you can use to break in but (and please do not take this personally) they can get a bit advanced - look at the Interrupting a running function tutorial in the Wiki if you want to see how it is done. Now, how to solve your immediate problem. The easiest way to keep the majority of your script intact is to use a single idle loop for both GUI and Tray messages - which is what you have here:expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=shout.ico #AutoIt3Wrapper_Outfile=iteration.exe #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; #include <GUIConstants.au3> ; <<<<<<<<<<<<<<<<<< Deprecated #include <GUIConstantsEx.au3> ; FileInstall("shout.ico", "shout.ico", 0) ; <<<<<<<<<<<<<<<<<< Not needed if you use the #AutoIt3Wrapper_Icon directive Opt("TrayMenuMode", 3) ; Default tray menu items (Script Paused/Exit) will not be shown. ;Opt("TrayOnEventMode", 1) ; Enable Tray Events Opt("TrayAutoPause", 0) ; No Pause on Menu ; OnAutoItExitRegister("MyExit") ; <<<<<<<<<<<<<<<<<< You already cover all exit cases Global $NameVersion = "iTeration 1.04" Global $GUIid = "", $Start, $Stop, $Timer, $Display ;#NoTrayIcon ; You want an icon for the menu! Global $begin = 0, $click = 0, $EndVar = 0, $NowVar = -1 ; Create Tray Menu $iTerationItem = TrayCreateItem("Go") TrayCreateItem("") ; seperation line $aboutItem = TrayCreateItem("About") TrayCreateItem("") ; seperation line $exitItem = TrayCreateItem("Exit") TraySetState() While 1 ; Look for GUI events Switch GUIGetMsg() Case $GUI_EVENT_CLOSE IniWrite("iTeration.ini", "Starting Value", "Input", GUICtrlRead($Timer)) MyExit() Case $Stop Stop() Case $Start GUICtrlSetState($Timer, $GUI_DISABLE) GUICtrlSetState($Start, $GUI_DISABLE) GUICtrlSetState($Stop, $GUI_ENABLE) ; GUICtrlSetData ($Display, $ms) $begin = TimerInit() $EndVar = MinutesToMillseconds(GUICtrlRead($Timer)) $click = 0 WinSetOnTop($GUIid, "", 1) IniWrite("iTeration.ini", "Starting Value", "Input", GUICtrlRead($Timer)) EndSwitch ; Look for tray events Switch TrayGetMsg() Case $exitItem IniWrite("iTeration.ini", "Starting Value", "Input", GUICtrlRead($Timer)) MyExit() Case $iTerationItem StartMain() Case $aboutItem aboutMsg() EndSwitch If $NowVar >= $EndVar Then Stop() Beep(1000, 200) Beep(400, 400) EndIf If $begin <> 0 Then $NowVar = TimerDiff($begin) $DispVar = MillsecondsToMinutes($NowVar) If $DispVar > Floor($click) Then $dummy = StringFormat("%3u", Ceiling(GUICtrlRead($Timer) - $DispVar)) ; ("%%.2f = '%.2f'\n", $ms) GUICtrlSetData($Display, $dummy) $click = Floor($DispVar) EndIf EndIf WEnd Func Stop() $begin = 0 GUICtrlSetState($Timer, $GUI_ENABLE) GUICtrlSetState($Start, $GUI_ENABLE) GUICtrlSetState($Stop, $GUI_DISABLE) ; WinSetOnTop ( $GUIid, "", 0) $NowVar = -1 EndFunc Func MyExit() Local $WPos[4] $WPos = WinGetPos($GUIid) IniWrite("iTeration.ini", "Starting Value", "Window Left", $WPos[0]) IniWrite("iTeration.ini", "Starting Value", "Window Top", $WPos[1]) Exit EndFunc ;==>MyExit Func aboutMsg() Local $message $message = $NameVersion & @CRLF & @CRLF $message = $message & "by Garth Bigelow" $message = $message & @CRLF & "With the infinite patience of the AutoIt Help Forums" & @CRLF $message = $message & @CRLF & "no rights reserved" MsgBox(64, "about:", $message) EndFunc ;==>aboutMsg Func StartMain() $WinWidth = 280 ;$WinX = @DesktopWidth - $WinWidth - 2 $SepY = 30 $ButWidth = 100 ; 80 $inputStart = IniRead("iTeration.ini", "Starting Value", "Input", "17") $WinX = IniRead("iTeration.ini", "Starting Value", "Window Left", @DesktopWidth - $WinWidth - 2) $WinY = IniRead("iTeration.ini", "Starting Value", "Window Top", $SepY) $GUIid = GUICreate($NameVersion, $WinWidth, 100, $WinX, $WinY) GUICtrlCreateLabel("Minutes", 10, $SepY, 48, $SepY - 4) ;GUICtrlSetBkColor(-1, 0xFF0000) $Timer = GUICtrlCreateInput($inputStart, 70, $SepY - 10, 50, $SepY) $updown = GUICtrlCreateUpdown($Timer) GUICtrlSetLimit($updown, 250, 1) $Display = GUICtrlCreateInput(" ", 70, $SepY + 30, 50, $SepY - 10) GUICtrlSetState($Display, $GUI_DISABLE) ;GUICtrlSetColor($Display, 0x00ffff) $Start = GUICtrlCreateButton("Start", ($WinWidth - $ButWidth - 10), $SepY - 18, $ButWidth, $SepY) $Stop = GUICtrlCreateButton("Stop", ($WinWidth - $ButWidth - 10), $SepY + 40 - 18, $ButWidth, $SepY) GUICtrlSetState($Stop, $GUI_DISABLE) GUISetState() EndFunc ;==>StartMain Func MillsecondsToMinutes($milli) $minutes = $milli / 60000 Return $minutes EndFunc ;==>MillsecondsToMinutes Func MinutesToMillseconds($milli) $minutes = $milli * 60000 Return $minutes EndFunc ;==>MinutesToMillsecondsA couple of points on the changes I have made:- 1. I hope the change to a single loop is obvious and the explanation above sufficient to show why it now works.- 2. I have rearranged a bit of the structure - all Opts are grouped together at the beginning for example, and all functions follow the main loop. Having a standard structure is a good habit to get into - and it makes debugging a lot easier!- 3. I had to add a few more Global variables to avoid errors when the code looked for controls that only appear when the GUI is present. Another way to get round this would be to create the GUI at the start and then hide/show it as necessary. - 4. I have commented out a few lines and explained why (look for <<<<<<< lines).If you have any questions, please ask - that is why we are 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...
JAFN Posted April 15, 2011 Author Share Posted April 15, 2011 I have been away for a bit or I would have responded earlier. Thank you for your time and effort. This has given me a lot to learn from as well as giving me thoughts on structure which is very well received. I think I understand the bulk of what you have done. There is a change I want to make and if I successful, I will feel confident that I understand. Again, thank you. As always, one other thing. A friend of mine needs a small list of about 200 to 300 title. He would like to sort it by title and by group + title. It seems like another excellent opportunity to learn. But before I reinvent the wheel, can you point me towards a library that deals with databases and indexing? [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
JAFN Posted April 15, 2011 Author Share Posted April 15, 2011 I have been away for a bit or I would have responded earlier. Thank you for your time and effort. This has given me a lot to learn from as well as giving me thoughts on structure which is very well received. I think I understand the bulk of what you have done. There is a change I want to make and if I successful, I will feel confident that I understand. Again, thank you. As always, one other thing. A friend of mine needs a small list of about 200 to 300 title. He would like to sort it by title and by group + title. It seems like another excellent opportunity to learn. But before I reinvent the wheel, can you point me towards a library that deals with databases and indexing? [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 15, 2011 Moderators Share Posted April 15, 2011 JAFN,a small list of about 200 to 300 title...to sort it by title and by group + titleBy the sound of it you are talking of MP3 files, so you can probably do it using the available Array and ListView functions. A database solution seems a little OTT to me for so few items.As I mentioned before, if you can be more specific when you ask questions, you will get more pertinent advice. 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...
JAFN Posted April 15, 2011 Author Share Posted April 15, 2011 I'll try. It is for his video/DVD collection which he has been offloading on eBay, etc. He wants to be able to keep track of what is where and to print lists over at least two sub categories. If ListViews are self organizing that would be ideal. [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 15, 2011 Moderators Share Posted April 15, 2011 JAFN, ListViews can be ordered by individual column. However arrays can, if you write the code, be ordered in groups. I am fairly sure that there are scripts on the forum that can do this. I will look for one tomorrow - or write one myself. 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...
JAFN Posted April 15, 2011 Author Share Posted April 15, 2011 I have just finished making changes to the code you cleaned for me. That coding is so intuitive. The change, making closing the window just drop back to the tray, took seconds because of it. I learned a lot and will strive to make future projects this clean. As to the new project you are saying I should keep all the data in memory, order it by code for the various needs and dump it to file when done. I think I can code this. Or at least try Thanks again. [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 16, 2011 Moderators Share Posted April 16, 2011 JAFN, As to the new project you are saying I should keep all the data in memory, order it by code for the various needs and dump it to file when doneYes. And here is a short snippet of code to show how you can order an array in groups to help you on your way: expandcollapse popup#include <Array.au3> ; Create a mixed-up array Global $aArray[9][2] = [ _ ["C", 1], _ ["A", 1], _ ["B", 1], _ ["C", 3], _ ["B", 2], _ ["A", 2], _ ["B", 3], _ ["A", 3], _ ["C", 2]] _ArrayDisplay($aArray, "Raw Data") ; Sort on first column _ArraySort($aArray) _ArrayDisplay($aArray, "Initial Sort") ; Now to sort second column within groups ; Set initial values to bound array $iBegin = 0 $iFinal = UBound($aArray) - 1 ; Now we move down the array While 1 ; This is the group value we are looking for $vValue = $aArray[$iBegin][0] ; So look for first row not to match it For $iRow = $iBegin To $iFinal If $aArray[$iRow][0] <> $vValue Then ExitLoop ; No match to exit the loop EndIf Next ; We now point to the final group entry + 1 so move back 1 $iEnd = $iRow - 1 ; And we now sort this section on the second column _ArraySort($aArray, 0, $iBegin, $iEnd, 1) _ArrayDisplay($aArray, "Sorted " & $iBegin & " - " & $iEnd) ; Check we are not at end of loop If $iRow > $iFinal Then ExitLoop ; This is the escape route when we hit the bottom of the array EndIf ; Reset the Begin value for the next loop $iBegin = $iRow WEnd _ArrayDisplay($aArray, "Final") You know where we are if you run into problems. 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...
JAFN Posted April 16, 2011 Author Share Posted April 16, 2011 I'm starting to think something went wrong with arrays in my system. But it is more likely me. Can you tell me why this errors out? Func Load_Array() Local $FileLines, $TempRow $FileLines = _FileCountLines($DataFileName) Global $Data[$FileLines][4] _FileReadToArray($DataFileName, $Data) For $a = 1 To $FileLines $TempRow = StringSplit($Data[$a],"*") ; msgbox(0, $FileLines, $TempRow[1] & " . " & $TempRow[2] & " . " & $TempRow[3] & " . " & $TempRow[4]) $Data[$a][1] = $TempRow[1] $Data[$a][2] = $TempRow[2] $Data[$a][3] = $TempRow[3] $Data[$a][4] = $TempRow[4] Next _ArrayDisplay($Data) EndFunc I think it is self-contained except for $DataFileName. The file is attached. Had to change the extension from .garth to .txt to attach it. It errors out right after the msgbox comment. I changed from the more concise '$Data[$a] = $TempRow' as an attempt at figuring out my misunderstanding. If you can once again, show me my obvious flaw I would appreciate it. Thank you.DvdLister.au3Titles.txt [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 16, 2011 Moderators Share Posted April 16, 2011 JAFN, I'm starting to think something went wrong with arrays in my system. But it is more likely meI am afraid so! Some explanation: - _FileReadToArray always produces a 1D array - even if you declared the array as something else earlier. So your 2D array Global $Data[$FileLines][4] became a 1D array after the function call. Thus you got an error when you tried to access the (now nonexistant) 2D elements. - Furthermore, you used the element indices [1]-[4] where an array with 4 elements has the indices [0]-[3]. Take a look at this amended function and you will see how it should (might) look: Func Load_Array() Local $FileLines, $TempRow, $Lines _FileReadToArray($DataFileName, $Lines) _ArrayDisplay($Lines) ; See how you get an automatic 1D array? Global $Data[$Lines[0] + 1][4] ; Now you can declare the 2D array using the count - no meed for _FileCountLines For $a = 1 To $Lines[0] $TempRow = StringSplit($Lines[$a], "*") $Data[$a][0] = $TempRow[1] $Data[$a][1] = $TempRow[2] $Data[$a][2] = $TempRow[3] $Data[$a][3] = $TempRow[4] Next _ArrayDisplay($Data) ; And you have your data EndFunc ;==>Load_Array As always, please ask if you have any questions. 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...
JAFN Posted April 16, 2011 Author Share Posted April 16, 2011 I'm lost on that one. However the sun has gone down and with it my ability to think. I will attack it fresh in the morning. Can you give me a few hints (just names of the functions involved. I really want to try to do it myself) on accessing the array in a set position as part of a window? I'll be back tomorrow. [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 17, 2011 Moderators Share Posted April 17, 2011 JAFN,I'm lost on that oneThen please ask questions once your brain is back in a receptive mood. accessing the array in a set position as part of a windowI am afraid that you have lost me there. Do you mean displaying the contents of the array within a GUI? If so, then a ListView is the way to go - look at GUICtrlCreateListView in the Help file. 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...
JAFN Posted April 17, 2011 Author Share Posted April 17, 2011 okay, I think I first get lost here. _FileReadToArray($DataFileName, $Lines) If this returns a 1D array haven't we lost data from the file? and _ArrayDisplay($Lines) ; See how you get an automatic 1D array? Didn't we are already have a 1D array on the _FileReadToArray line? and perhaps lastly Global $Data[$Lines[0] + 1][4] ; Now you can declare the 2D array using the count - no meed for _FileCountLines In redefining the variable don't we lose the original data? Assuming no, how does the file data lost from the 1D array magically reappear. Other than that I think I understand [size="2"]The second mouse gets the cheese[/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