BSoft Posted July 25, 2015 Share Posted July 25, 2015 (edited) Hi, I have an array of Check Box controls and want to provide a common handler function that can be called with the CheckBox Index as the parameter. Is there a way to detect when any CheckBox in an array of CheckBoxes is clicked and call a common handler function and pass the index of the CheckBox that was clicked to the common function?At the moment I am doing this manually and it seems a little messy - especially if I were to increase the number of Check Boxes in the array. (See sample code below); Create CheckBoxes for each Market in an Array $i = 0 $iSpacing = 24 While $i < $g_iMarketCount $temp = $g_MarketIdProc[$i] $g_CtrlMarketCheckBox[$i] = GUICtrlCreateCheckbox($temp, 80, $iSpacing, 65, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) $i = $i + 1 $iSpacing = $iSpacing + 20 WEndThen in my loop I haveexpandcollapse popupWhile 1 $nMsg = GUIGetMsg() Switch $nMsg Case $g_CtrlMarketCheckBox[0] MyUpdateMarket(0) Case $g_CtrlMarketCheckBox[1] MyUpdateMarket(1) Case $g_CtrlMarketCheckBox[2] MyUpdateMarket(2) Case $g_CtrlMarketCheckBox[3] MyUpdateMarket(3) Case $g_CtrlMarketCheckBox[4] MyUpdateMarket(4) Case $g_CtrlMarketCheckBox[5] MyUpdateMarket(5) Case $g_CtrlMarketCheckBox[6] MyUpdateMarket(6) Case $g_CtrlMarketCheckBox[7] MyUpdateMarket(7) Case $g_CtrlMarketCheckBox[8] MyUpdateMarket(8) Case $g_CtrlMarketCheckBox[9] MyUpdateMarket(9) Case $g_CtrlMarketCheckBox[10] MyUpdateMarket(10) Case $g_CtrlMarketCheckBox[11] MyUpdateMarket(11) Case $g_CtrlMarketCheckBox[12] MyUpdateMarket(12) Case $g_CtrlMarketCheckBox[13] MyUpdateMarket(13) Case $g_CtrlMarketCheckBox[14] MyUpdateMarket(14) EndSwitch WEndIt would be nice to be able to replace this with just a single common function call. Edited July 25, 2015 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 25, 2015 Moderators Share Posted July 25, 2015 BSoft,A simple loop through the array checking the stored ControlID against $nMsg would seem to meet your requirements:#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> Global $g_iMarketCount = 10 Global $g_CtrlMarketCheckBox[$g_iMarketCount] $hGUI = GUICreate("Test", 500, 500) ; Create CheckBoxes for each Market in an Array $iSpacing = 24 For $i = 0 To $g_iMarketCount - 1 $g_CtrlMarketCheckBox[$i] = GUICtrlCreateCheckbox($i, 80, $iSpacing + (20 * $i), 65, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) Next GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case Else For $i = 0 To $g_iMarketCount - 1 If $g_CtrlMarketCheckBox[$i] = $nMsg Then MsgBox($MB_SYSTEMMODAL, "Pressed", $i) ; No point in looking further ExitLoop EndIf Next EndSwitch WEndI simplified the creation code a bit as well.M23P.S. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. 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...
BSoft Posted July 25, 2015 Author Share Posted July 25, 2015 Thank you again Melba23. Simple and very clean!Thank you also for the tip re posting - will do in future now. Link to comment Share on other sites More sharing options...
LarsJ Posted July 25, 2015 Share Posted July 25, 2015 The "Case Else" can be optimized:Case $g_CtrlMarketCheckBox[0] To $g_CtrlMarketCheckBox[$g_iMarketCount-1] MsgBox($MB_SYSTEMMODAL, "Pressed", $nMsg - $g_CtrlMarketCheckBox[0]) Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 25, 2015 Moderators Share Posted July 25, 2015 LarsJ,True - if the checkboxes are created in immediate succession, which normally results in an array of consecutive ControlIDs. But this is undocumented and not guaranteed (especially if other controls have been deleted previously) so I would always recommend using the method I posted.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...
spudw2k Posted July 30, 2015 Share Posted July 30, 2015 For reference, you can also use OnEvent instead of a GetMSG loop and utilize @CtrlID as an alternative.Here's a link to an example which demonstrates what I mean.Clicking a Checkbox calls the _Clicked function and the function interacts with @CtrlIDDepending on what your are trying to do with it of course, this may allow you to interact with a specific Checkbox control without having to track them in an Array--although I've certainly used an array to track controls in my scripts before Just wanted to give another ideas 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 BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool 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...
Guest Posted December 4, 2019 Share Posted December 4, 2019 Hi M23 I have started learning autoit scripts last week and your tips have been very helpful. I am trying to Read checkboxes from an existing array variable, and Modify the array based on the state of the checkboxes changing as they are being ticked. My array has my labels in the 3rd column, and the checkboxes start on column 5 (I have not included the array as it is so big. I have 2 issues: As I was trying to make it fit on screen, I had to either use scroll bars or use tabs; your one command scrollbar worked great, except the scrolling froze due to the size of the array; when I tried to split into tabs, all of the checkboxes and labels appear on the first tab and then every other tab is empty As I open the GUI, the positions marked as 1 in the array do not appear as checked (I am probably doing this wrong in my loop); because of this my script probably also isn't saving anything into the array with my loop You wrote in another threat that listview doesn't play nice with tabs, so I may be falling into the same kind of issue with array check boxes. For me it is important to have everything in an array because the check boxes will determine information to look for in another function of the script. I tried adding the tab closing statement in the for..to function for the last value of $i and $j and that also didn't work. Regarding having my tickmarks pre-checked based on the initials state of the array, I must admit I haven't yet started to explore my options. I would be really grateful if you could point me in the right direction. expandcollapse popup;~ $array_mods_[x][0] = Category ;~ $array_mods_[x][1] = Name ;~ $array_mods_[x][2] = Description ;~ $array_mods_[x][3] = Modstring ;~ $array_mods_[x][4-14] = checkmarks for each of the labels below $array_weaponmods[126][15] $ColLabels[11] = ["Axe", "Bow", "Offhand", "Hammer", "Wand", "Shield", "Staff", "Sword" , "Daggers", "Scythe", "Spear"] $g_iMarketCount = 50 $g_CtrlMarketCheckBox[$g_iMarketCount] $iSpacing = 8 Global $frmSelection = GUICreate("Mod Selection", 808, 624, 500, 112) GUICtrlCreateTab(8, 8, 792, 608) GUICtrlCreateTabItem("Popular Mods") For $i = 0 To 30 GUICtrlCreateLabel($array_weaponmods[$i+1][2], $X_GUI+$iSpacing, 60 + (20 * $i),200, $iSpacing*2) For $j = 4 to 14 If $i=0 then GUICtrlCreateLabel($ColLabels[$j-4], $X_GUI + 20+(50 * $j), 40 + (20 * $i), 40, $iSpacing*2, $ES_CENTER) $array_weaponmods[$i][$j] = GUICtrlCreateCheckbox("", $X_GUI + 20+(50 * $j), 60 + (20 * $i), 40, $iSpacing*2, $ES_CENTER) ; GUICtrlCreateCheckbox($array_weaponmods[$i][4], $iSpacing + 200 + (20 * $j), $iSpacing + (20 * $i), 96, $iSpacing * 2, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) ; GUICtrlCreateCheckbox($array_weaponmods[$i][2], $X_GUI+$iSpacing, $iSpacing + (20 * $i), 200, $iSpacing*2, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) Next Next GUICtrlCreateTabItem("") ; end tabitem definition GUICtrlCreateTabItem("Armor") For $i = 31 To 124 GUICtrlCreateLabel($array_weaponmods[$i+1][2], $X_GUI+$iSpacing, $iSpacing + (20 * ($i+1)),200, $iSpacing*2) For $j = 4 to 14 If $i=0 then GUICtrlCreateLabel($ColLabels[$j-4], $X_GUI + 20+(50 * $j), $Y_GUI + (20 * $i), 40, $iSpacing*2, $ES_CENTER) $array_weaponmods[$i][$j] = GUICtrlCreateCheckbox(" ", $X_GUI + 20+(50 * $j), $Y_GUI + 20 + (20 * $i), 40, $iSpacing*2, $ES_CENTER) ; GUICtrlCreateCheckbox($array_weaponmods[$i][4], $iSpacing + 200 + (20 * $j), $iSpacing + (20 * $i), 96, $iSpacing * 2, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) ; GUICtrlCreateCheckbox($array_weaponmods[$i][2], $X_GUI+$iSpacing, $iSpacing + (20 * $i), 200, $iSpacing*2, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE)) Next Next GUICtrlCreateTabItem("") ; end tabitem definition GUISetOnEvent($GUI_EVENT_CLOSE, "ExitBot") GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case Else For $i = 0 To 124 For $j = 4 to 14 If $array_weaponmods[$i][$j] = 1 then GUIctrlsetstate ($array_weaponmods[$i][$j], $GUI_CHECKED) Endif If $array_weaponmods[$i][$j] = $nMsg Then GUIctrlsetstate ($array_weaponmods[$i][$j], $GUI_CHECKED) ; No point in looking further ExitLoop EndIf Next Next EndSwitch WEnd I have attached a picture of the GUI, as you can see the rows beyond 24 should go onto the next tab but as it is now, they just overflow in the first tab. :-( Link to comment Share on other sites More sharing options...
Nine Posted December 4, 2019 Share Posted December 4, 2019 I would strongly suggest that you read forum rules, especially the part about game automation. As you will see, it is not allowed to discuss such matter in this forum. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Developers Jos Posted December 4, 2019 Developers Share Posted December 4, 2019 Welcome to the AutoIt forum. Unfortunately you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked. See you soon with a legitimate question I hope. The Moderation team 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...
Recommended Posts