Jump to content

read ini


Recommended Posts

hey i need a little help i cant figure this out..

i have a inputbox which has the standard value of "0" as you can see below

$earth1 = GUICtrlCreateInput("0", 45, 70, 55, 20)

so i open my gui and enter a different number and hit the save button and it writes the new value into the .ini file

$Button1 = GUICtrlCreateButton("Save", 350, 20, 55, 20)

While 1
        $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            INIWRITE("test.ini", "EARTH", "Earth 1", GUICtrlRead($earth1))
                        
        EndSwitch
WEnd
    GUIDelete()
EndFunc  ;==>Example1

what i want it to do is everytime i open the script again it should read the value of the ini file and replace the inputbox value with the new saved one

i.e. inputbox "0" .. i change it to "5" hit save its saved in the ini file.. i close my script open it again and the standard value is "5" .. change it to "77" hit save - saves it in the ini file.. i close the script again, open it again and the inputbox value is "77"

i dont know how to do that.. the only thing what i did is i changed the inputbox to something like this

$ini=IniRead("test.ini", "EARTH", "Earth 1", "")
$earth1 = GUICtrlCreateInput($ini, 45, 70, 55, 20)

but then if i have no ini file and start the script the first time the inputbox will be blank - no value in it (if i enter a value - save - close the script - open it again, the new value will be shown) but id like the standard values to be "0" for the first time that i start the script

hope you understand my problem and can help me out thx

Link to comment
Share on other sites

Something like this works for me.

$inifile = @ScriptDir & "\test.ini"

$current_value = IniRead ($inifile, "section", "key", "default")
$input = InputBox ("Enter new value!", "Current value is: " & $current_value)
IniWrite ($inifile, "section", "key", $input)

$current_value = IniRead ($inifile, "section", "key", "default")
$input = MsgBox (0, "", "New value is: " & $current_value)
Link to comment
Share on other sites

how about:

$ini=IniRead("test.ini", "EARTH", "Earth 1", "")
if @error then $ini='0'
$earth1 = GUICtrlCreateInput($ini, 45, 70, 55, 20)

This will assign default '0' value to $ini.. if ur file doesn't exist..

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
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...