XY16 Posted May 8, 2011 Share Posted May 8, 2011 hi i wonder if anyone can help me with this little problem. i have an array of tray menu items. by the time the array is created i will not know how many elements it contains as it can vary depending on system configuration. how can i perform case statements on each element in the array but not go past the max index? Please note: If you plan on submitting any code snippits to my posts, please refrain from using the code tags as i use a screen reader and can't read the code properly, let alone copy it the way it should be.Thanks for your understanding.Best regardsXY16 Link to comment Share on other sites More sharing options...
smartee Posted May 8, 2011 Share Posted May 8, 2011 Hi, Look in the help file for UBound(). -smartee Link to comment Share on other sites More sharing options...
XY16 Posted May 8, 2011 Author Share Posted May 8, 2011 hi smartee ubound does in deed give me the max index, kinda like ArrayMaxIndex does, but i don't know where to start when performing case statements. i have tried using loops, an example is below. $Array[0] = TrayCreateItem("Item1") $Array[1] = TrayCreateItem("Item2") $Array[2] = TrayCreateItem("Item3") ;etc $Items = UBound($Array, "0") While 1 $msg = TrayGetMsg() $Count = "0" While 1 Select Case $msg = $Array[$Count] MsgBox(64, "Info", "Item " & $Count & " was selected.") if $Count > $Items then ExitLoop EndSelect WEnd WEnd this doesn't work. i would rather not use an array, but can't figure out how to create a variable named based on a counter, for example $MyVar$Counter. Any ideas? Please note: If you plan on submitting any code snippits to my posts, please refrain from using the code tags as i use a screen reader and can't read the code properly, let alone copy it the way it should be.Thanks for your understanding.Best regardsXY16 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 8, 2011 Moderators Share Posted May 8, 2011 XY16, This is one way to do it: #include <Array.au3> ; So we can finally exit HotKeySet("{ESC}", "On_Exit") ; Create the array Global $aArray[3] $aArray[0] = TrayCreateItem("Item1") $aArray[1] = TrayCreateItem("Item2") $aArray[2] = TrayCreateItem("Item3") ;etc ; So you can see the values - I get 7, 8, 9 _ArrayDisplay($aArray) ; Strat a timer to simulate a click on the tray $iBegin = TimerInit() ; Our idle loop While 1 ; Get the event - although here we will never change as there is no change! $iMsg = TrayGetMsg() ; Simulate a message after 1 Sec - change the value to change the result If TimerDiff($iBegin) > 1000 Then $iMsg = 8 ; Loop through the array to see if the value is within it For $iCount = 0 To UBound($aArray) - 1 If $iMsg = $aArray[$iCount] Then ; It is! MsgBox(64, "Info", "Item " & $iCount & " was selected.") ; And exit the For...Next loop - here you will get a continuous firing of the same value as there is no tray to change the value ExitLoop EndIf Next WEnd Func On_Exit() Exit EndFunc Please ask if anything is unclear. 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...
XY16 Posted May 8, 2011 Author Share Posted May 8, 2011 hi you're example was pretty strait forward, but how can the app tell what item someone clicked? Please note: If you plan on submitting any code snippits to my posts, please refrain from using the code tags as i use a screen reader and can't read the code properly, let alone copy it the way it should be.Thanks for your understanding.Best regardsXY16 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 8, 2011 Moderators Share Posted May 8, 2011 XY16,"how can the app tell what item someone clicked?" - You just use the $iCount variable. To make life easy, I would add another array (or another dimension in the same array as I have shown below) which tells the app what function to run when that particular item is clicked:#include <Array.au3>; So we can finally exitHotKeySet("{ESC}", "On_Exit"); Create the arrayGlobal $aArray[3][2] ; [0] is ControlID, [1] is function to run$aArray[0][0] = TrayCreateItem("Item1")$aArray[0][1] = "Function_0"$aArray[1][0] = TrayCreateItem("Item2")$aArray[1][1] = "Function_1"$aArray[2][0] = TrayCreateItem("Item3")$aArray[2][1] = "Function_3";etc; So you can see the values - I get 7, 8, 9_ArrayDisplay($aArray); Strat a timer to simulate a click on the tray$iBegin = TimerInit(); Our idle loopWhile 1; Get the event - although here we will never change as there is no change!$iMsg = TrayGetMsg(); Simulate a message after 1 Sec - change the value to change the resultIf TimerDiff($iBegin) > 1000 Then $iMsg = 8; Loop through the array to see if the value is within itFor $iCount = 0 To UBound($aArray) - 1If $iMsg = $aArray[$iCount][0] Then; It is!Call($aArray[$iCount][1]); And exit the For...Next loop - here you will get a continuous firing of the same value as there is no tray to change the valueExitLoopEndIfNextWEndFunc Function_0()MsgBox(0, "Hit!", "The user clicked Item 0")EndFuncFunc Function_1()MsgBox(0, "Hit!", "The user clicked Item 1")EndFuncFunc Function_2()MsgBox(0, "Hit!", "The user clicked Item 2")EndFuncFunc On_Exit()ExitEndFuncAll 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...
XY16 Posted May 8, 2011 Author Share Posted May 8, 2011 hi that's loads clearer. i don't think i've been functioning at full capacity this morning due to the fact that i've only just eaten. thanks allott for your help. that's made my life easier. Please note: If you plan on submitting any code snippits to my posts, please refrain from using the code tags as i use a screen reader and can't read the code properly, let alone copy it the way it should be.Thanks for your understanding.Best regardsXY16 Link to comment Share on other sites More sharing options...
XY16 Posted May 8, 2011 Author Share Posted May 8, 2011 to add to my last post, i think it wasn't working properly for me because the TrayAutoPause option is enabled by default, i disabled id it and now everything works fine. once again thanks for all you're help. Please note: If you plan on submitting any code snippits to my posts, please refrain from using the code tags as i use a screen reader and can't read the code properly, let alone copy it the way it should be.Thanks for your understanding.Best regardsXY16 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