Jump to content

Newbie problem, combobox allways writes 0 to .ini


Karting
 Share

Recommended Posts

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.

#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.
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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]

try

Local $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:

Elseif

Select

Switch

Case

Enjoy.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...