BatMan22 Posted March 12, 2022 Share Posted March 12, 2022 Hi guys so I'm stuck mentally about how to design a GUI where the number of selections vary run to run. I tried playing around with the code below but of course that's not going to generate unique variables so I can read those controls for responses.. The only thing I can think of is that the gui has to have everything predefined but hidden...Am I correct? for example $Label1, $Label2, $Label3, $Label4, $Label5, .... $combo1, $combo2, $combo3... But thats going to get very tedious, is that the only way? I would generally expect the "$selectionList" to contain 20 or less variable.. Basically I need to re-created array display but with the ability for the user to select from a combo box. ;Expanding Gui Test #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Local $SelectionList[3] = ["element 1", "element 2", "element 3"] #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 447, 464, 192, 124) $LabelRRLog = GUICtrlCreateLabel("RR Log?", 352, 8, 47, 17) $Combo1 = GUICtrlCreateCombo("Combo1", 352, 32, 81, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $LabelText = GUICtrlCreateLabel("Text#1", 16, 32, 324, 17) For $i = 0 to UBound($SelectionList) $Label3 = GUICtrlCreateLabel("Text#2", 16, (32 + ($i * 16)), 328, 25) $Combo2 = GUICtrlCreateCombo("Combo2", 352, (32 + ($i * 16)) , 81, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) Next GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
jchd Posted March 12, 2022 Share Posted March 12, 2022 Use an array to store the control IDs, not individual variables. BatMan22 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted March 12, 2022 Moderators Solution Share Posted March 12, 2022 BatMan22, I an not quite sure what you are looking to do, but here is how you can deal with variable numbers of controls: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <ComboConstants.au3> #include <MsgBoxConstants.au3> ; Initial random count $iCount = Random(1, 20, 1) ; Fill combo Local $aSelectionList[20] For $i = 0 To 19 $aSelectionList[$i] = "Selection " & $i Next ; Arrays to hold CIDs Global $aLabel[20], $aCombo[20] ; Create GUI $hGUI = GUICreate("Form1", 500, 500) $cLabelRRLog = GUICtrlCreateLabel("RR Log?", 300, 10, 50, 20) $cCombo1 = GUICtrlCreateCombo("", 350, 10, 80, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData($cCombo1, _ArrayToString($aSelectionList)) _DrawControls() GUISetState(@SW_SHOW) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $cCombo1 ; Main combo selected - delete and redraw controls _DeleteControls() $iCount = Random(1, 20, 1) ; New count _DrawControls() Case Else ; Look to see whic combo was activated For $i = 0 To $iCount - 1 If $iMsg = $aCombo[$i] Then MsgBox($MB_SYSTEMMODAL, "Combo activated", $i) Exitloop EndIf Next EndSwitch WEnd Func _DrawControls() For $i = 0 To $iCount - 1 $aLabel[$i] = GUICtrlCreateLabel("Text#" & $i, 20, 35 + ($i * 25), 300, 20) $aCombo[$i] = GUICtrlCreateCombo("Combo#" & $i, 350, 35 + ($i * 25), 80, 25) Next EndFunc Func _DeleteControls() For $i = 0 To $iCount - 1 GUICtrlDelete($aLabel[$i]) GUICtrlDelete($aCombo[$i]) Next EndFunc Actioning the main combo will change the number of other combos, actioning each of which results in a MsgBox. If you can give a better description of exactly what you want, we can refine the script. M23 BatMan22 1 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...
BatMan22 Posted March 12, 2022 Author Share Posted March 12, 2022 Jesus.. THIS is why I'll never be a real programmer. I would have spent hours writing out variable / control names instead of just realizing that the handle for the controls could be stored in an array itself. So simple, I feel dumb but also excited to try it. Thanks @jchd and @Melba23 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