Karting Posted January 11, 2012 Posted January 11, 2012 Hi all, Here is simple GUI code, that controls sleep times in actual script. I allways get "0" saved to .ini file. I think the problem is where i make the comboboxes but dont know how to write them correctly. expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ;~ This reads the current value for the selection boxes If IniRead("settings.ini","adtimes","ad1_lenght","5000") = 5000 Then local $ad1_lenght = "5 sec" endif If IniRead("settings.ini","adtimes","ad1_lenght","5000") = 10000 Then local $ad1_lenght = "10 sec" endif If IniRead("settings.ini","adtimes","ad1_lenght","5000") = 15000 Then local $ad1_lenght = "15 sec" endif If IniRead("settings.ini","adtimes","ad1_lenght","5000") = 0 Then local $ad1_lenght = "Off" endif If IniRead("settings.ini","adtimes","ad2_lenght","5000") = 5000 Then local $ad2_lenght = "5 sec" endif If IniRead("settings.ini","adtimes","ad2_lenght","5000") = 10000 Then local $ad2_lenght = "10 sec" endif If IniRead("settings.ini","adtimes","ad2_lenght","5000") = 15000 Then local $ad2_lenght = "15 sec" endif If IniRead("settings.ini","adtimes","ad2_lenght","5000") = 0 Then local $ad2_lenght = "Off" endif If IniRead("settings.ini","adtimes","ad3_lenght","5000") = 5000 Then local $ad3_lenght = "5 sec" endif If IniRead("settings.ini","adtimes","ad3_lenght","5000")= 10000 Then local $ad3_lenght = "10 sec" endif If IniRead("settings.ini","adtimes","ad3_lenght","5000")= 15000 Then local $ad3_lenght = "15 sec" endif If IniRead("settings.ini","adtimes","ad3_lenght","5000")= 0 Then local $ad3_lenght = "Off" endif If IniRead("settings.ini","adtimes","ad4_lenght","5000")= 5000 Then local $ad4_lenght = "5 sec" endif If IniRead("settings.ini","adtimes","ad4_lenght","5000")= 10000 Then local $ad4_lenght = "10 sec" endif If IniRead("settings.ini","adtimes","ad4_lenght","5000")= 15000 Then local $ad4_lenght = "15 sec" endif If IniRead("settings.ini","adtimes","ad4_lenght","5000")= 0 Then local $ad4_lenght = "Off" endif $Form1_1 = GUICreate("Form1", 615, 438, 192, 124) $Label1 = GUICtrlCreateLabel("Ad 1 lenght", 104, 220, 58, 17) $Label2 = GUICtrlCreateLabel("Ad 2 lenght", 104, 260, 58, 17) $Label3 = GUICtrlCreateLabel("Ad 3 lenght", 104, 300, 58, 17) $Label4 = GUICtrlCreateLabel("Ad 4 lenght", 104, 340, 58, 17) $Savebutton = GUICtrlCreateButton("Save settings", 208, 376, 75, 25) $Sel_time1 = GUICtrlCreateCombo("Off", 175, 220, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Sel_time1 = GUICtrlSetData (-1, "5 sec|10 sec|15 sec", $ad1_lenght) $Sel_time2 = GUICtrlCreateCombo("Off", 175, 260, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Sel_time2 = GUICtrlSetData (-1, "5 sec|10 sec|15 sec", $ad2_lenght) $Sel_time3 = GUICtrlCreateCombo("Off", 175, 300, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Sel_time3 = GUICtrlSetData (-1, "5 sec|10 sec|15 sec", $ad3_lenght) $Sel_time4 = GUICtrlCreateCombo("Off", 175, 340, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Sel_time4 = GUICtrlSetData (-1, "5 sec|10 sec|15 sec", $ad4_lenght) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() if $msg = -3 then Exit if $msg = $Savebutton then Savebutton() ;When savebutton is saved, then execute savebutton function WEnd Func Savebutton () ;Read the values from Comboboxes, manipulate and save to .ini file in numeric format if GUICtrlRead($Sel_time1) = "Off" then $ad1_newini = "0" if GUICtrlRead($Sel_time1) = "5 sec" then $ad1_newini = "5000" if GUICtrlRead($Sel_time1) = "10 sec" then $ad1_newini = "10000" if GUICtrlRead($Sel_time1) = "15 sec" then $ad1_newini = "15000" if GUICtrlRead($Sel_time2) = "Off" then $ad2_newini = "0" if GUICtrlRead($Sel_time2) = "5 sec" then $ad2_newini = "5000" if GUICtrlRead($Sel_time2) = "10 sec" then $ad2_newini = "10000" if GUICtrlRead($Sel_time2) = "15 sec" then $ad2_newini = "15000" if GUICtrlRead($Sel_time3) = "Off" then $ad3_newini = "0" if GUICtrlRead($Sel_time3) = "5 sec" then $ad3_newini = "5000" if GUICtrlRead($Sel_time3) = "10 sec" then $ad3_newini = "10000" if GUICtrlRead($Sel_time3) = "15 sec" then $ad3_newini = "15000" if GUICtrlRead($Sel_time4) = "Off" then $ad4_newini = "0" if GUICtrlRead($Sel_time4) = "5 sec" then $ad4_newini = "5000" if GUICtrlRead($Sel_time4) = "10 sec" then $ad4_newini = "10000" if GUICtrlRead($Sel_time4) = "15 sec" then $ad4_newini = "15000" IniWrite("settings.ini","adtimes","ad1_lenght",$ad1_newini) IniWrite("settings.ini","adtimes","ad2_lenght",$ad2_newini) IniWrite("settings.ini","adtimes","ad3_lenght",$ad3_newini) IniWrite("settings.ini","adtimes","ad4_lenght",$ad4_newini) MsgBox(0,"RShow", "Settings have been saved",1) EndFunc ;Continue running the while loop.
Moderators Melba23 Posted January 11, 2012 Moderators Posted January 11, 2012 Karting,You are overwriting the ControlID of your combos when you do this:$Sel_time1 = GUICtrlCreateCombo("Off", 175, 220, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) $Sel_time1 = GUICtrlSetData (-1, "5 sec|10 sec|15 sec", $ad1_lenght)So when you try to read the combos, the variable holds 1 - the return value from a successful GUICtrlSetData.If you do not over write the variable, all will work properly:$Sel_time1 = GUICtrlCreateCombo("Off", 175, 220, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData (-1, "5 sec|10 sec|15 sec", $ad1_lenght)All 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
TomSmith Posted January 11, 2012 Posted January 11, 2012 I know this isn't a fix for your problem but I signed up when I saw this in your code, If IniRead("settings.ini","adtimes","ad1_lenght","5000") = 5000 Then local $ad1_lenght = "5 sec" endif If for any reason you change the working directory, iniread wont see settings.ini and will return default. This is my code really quick.. iniread(@ScriptDir&"\config.ini", "1", "Nick", "ERROR") The @ScriptDir&"\ makes sure you always get the value if the ini is setup properly and exists. Hopefully I can save you some headache should this error ever happen for you. It destroyed me for a few hours lol
Karting Posted January 12, 2012 Author Posted January 12, 2012 Thanks for both! The solution was obvious when i saw it. I Knew the problem was there.... And what comes to @ScriptDir&", i noticed it some other script i was looking and thought i must check what it is later. Anyways, this works now ill ask more for help soon
Mikeman27294 Posted January 12, 2012 Posted January 12, 2012 Also, instead of[color=#000000]If IniRead("settings.ini","adtimes","ad1_lenght","5000") = 5000 Then[/color] local $ad1_lenght = "5 sec" endif If IniRead("settings.ini","adtimes","ad1_lenght","5000") = 10000 Then local $ad1_lenght = "10 sec" endif If IniRead("settings.ini","adtimes","ad1_lenght","5000") = 15000 Then local $ad1_lenght = "15 sec" endif If IniRead("settings.ini","adtimes","ad1_lenght","5000") = 0 Then local $ad1_lenght = "Off" [color=#000000]endif[/color]tryLocal $Ad1Length = [color=#000000]IniRead("settings.ini","adtimes","ad1_lenght","5000")[/color] [color=#000000]$Ad1Length = $Ad1Length/1000[/color] [color=#000000]Like that, you save on loads of code. You might also like to look into the following commands:ElseifSelectSwitchCaseEnjoy.
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