Jump to content

Need help. I want my GUI combobox to remember the last dropdown item the user use.


Go to solution Solved by It_is_me_Me,

Recommended Posts

I am making some GUI with combobox for the Baudrates communications and I listed 9600, 57600, 115200. 

I wrote the code to be defaulted to 57600 like this:

GUICtrlSetData($comboBox_opticalBaudRate, "9600|57600|115200", "57600")

But I wanted the GUI to remember the last item the user picks so the baudrates will NOT be defaulted to 57600.

Example, I pick 9600 as my baudrates, then I close the GUI, after opening it, it always prompt 57600 since that is what I did in my code. But I want that if I choose 9600 and close the GUI, opening it again will show 9600 now instead of 57600.

Is there a way to do it in GUI setting?

 

Thanks.

Edited by It_is_me_Me
Link to comment
Share on other sites

  • 3 weeks later...
  • Solution
;Sample only. I only pick these two lines of code but actually they are more and are linked to the code below it.

Global $input_tcpPort = GUICtrlCreateInput("502", 196, 81, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlSetData($input_tcpPort, IniRead ("Ini File.ini", "TCP", "Port", ""))


Case $btn_runTest
            ;--GUI INI File Start--
            IniWrite('Ini File.ini', "Serial-485", "Protocol", GUICtrlRead($comboBox_serialProtocol))
            IniWrite("Ini File.ini", "Serial-485", "BaudRate", GUICtrlRead($comboBox_serialBaudrate))
            IniWrite("Ini File.ini", "Serial-485", "Port", GUICtrlRead($comboBox_serialPort))
            IniWrite("Ini File.ini", "Serial-485", "Address", GUICtrlRead($input_serialAddress))

            IniWrite('Ini File.ini', "USB", "Protocol", GUICtrlRead($comboBox_usbProtocol))
            IniWrite("Ini File.ini", "USB", "BaudRate", GUICtrlRead($comboBox_usbBaudrate))
            IniWrite("Ini File.ini", "USB", "Port", GUICtrlRead($comboBox_usbPort))
            IniWrite("Ini File.ini", "USB", "Address", GUICtrlRead($input_usbAddress))

            IniWrite('Ini File.ini', "Optical", "Protocol", GUICtrlRead($comboBox_opticalProtocol))
            IniWrite("Ini File.ini", "Optical", "BaudRate", GUICtrlRead($comboBox_opticalBaudrate))
            IniWrite("Ini File.ini", "Optical", "Port", GUICtrlRead($comboBox_opticalPort))
            IniWrite("Ini File.ini", "Optical", "Address", GUICtrlRead($input_opticalAddress))

            IniWrite("Ini File.ini", "TCP", "Address", GUICtrlRead($input_tcpDevAddress))
            IniWrite("Ini File.ini", "TCP", "Port", GUICtrlRead($input_tcpPort))

SO I made some adjustments to my code. I just use INI file so the script can get its data from it.

Link to comment
Share on other sites

Here is a working example:

 

;Help example file:  _GUICtrlComboBox_GetCurSel.au3
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Create GUI
    GUICreate("ComboBox Get/Set Cur Sel (v" & @AutoItVersion & ")", 400, 296)
    Local $idCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    GUICtrlSetData($idCombo, "9600|57600|115200", "57600")
    GUISetState(@SW_SHOW)


    Local $init=IniRead(@ScriptDir & "settings.ini","OnLoadSettings","Baudrate",0)
    ; Select Item
    _GUICtrlComboBox_SetCurSel($idCombo, $init)

    While 1
    $nmsg=GUIGetMsg()
        Switch $nmsg
            Case $GUI_EVENT_CLOSE
                IniWrite (@ScriptDir & "settings.ini","OnLoadSettings","Baudrate",_GUICtrlComboBox_GetCurSel($idCombo))
                GUIDelete()
                EXIT
        EndSwitch
    WEnd

EndFunc   ;==>Example

 

Some of my script sourcecode

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...