grasshopper3 Posted February 17, 2011 Share Posted February 17, 2011 I have create a program that has become ever expanding. Previously I was just writing the GUI control values to a config file and the restoring them when the program starts again. This method has become tedious because of the number of controls I have. Does anyone know of a way to easily grab the values of ALL the GUI controls for saving and loading? Would using a database be easier than a config file. I am looking at around 60 controls that looks to grow up to 100 with time. Thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 17, 2011 Moderators Share Posted February 17, 2011 grasshopper3,My 2p worth.If you put the ControlIDs of the controls into an array as they were created, then you could save and load them very quickly with a small function which looped through them and called GUICtrlRead or GUICtrlSetData as required. Personally, I would say that 100 control/value pairs is hardly worth the effort of a database and would be fine in an ini 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...
grasshopper3 Posted February 17, 2011 Author Share Posted February 17, 2011 is there a way to easily populate this array or do I have to hard code? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 17, 2011 Moderators Share Posted February 17, 2011 grasshopper3, You could do it like this: #include <GUIConstantsEx.au3> Global $aControlID[4] ; Set this to match the number of controls Global $sIniFile = @ScriptDir & "\Test.ini" $hGUI = GUICreate("Test", 500, 500) ; Create the control $hInput_A = GUICtrlCreateInput("", 10, 10, 200, 20) ; And save the ControlID in the Array $aControlID[0] = $hInput_A $hInput_B = GUICtrlCreateInput("", 10, 50, 200, 20) $aControlID[1] = $hInput_B $hInput_C = GUICtrlCreateInput("", 10, 90, 200, 20) $aControlID[2] = $hInput_C $hInput_D = GUICtrlCreateInput("", 10, 130, 200, 20) $aControlID[3] = $hInput_D ; Loop through the array to set the saved values For $i = 0 To 3 GUICtrlSetData($aControlID[$i], IniRead($sIniFile, "Data", $i, "Not found")) Next GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Loop through the array to save the current values For $i = 0 To 3 IniWrite($sIniFile, "Data", $i, GUICtrlRead($aControlID[$i])) Next Exit EndSwitch WEnd You coudl also put the ControlIDs directly into the array as the controls are created, but then you would have to remember which array element was which control. I think the code above is the best compromise - you get nice easy to use variables in your script and an array to loop through when needed. All clear? M23 GoogleGonnaSaveUs 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...
grasshopper3 Posted February 17, 2011 Author Share Posted February 17, 2011 Got it. Thanks! PS. I like your listview UDF I will have to find a use for it. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 17, 2011 Moderators Share Posted February 17, 2011 grasshopper3,I like your listview UDFThanks. 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...
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