Jump to content

Issue with iniwrite function


Recommended Posts

Hey guys, I have created a simple GUI here and now I want to be able to use the two browse buttons and have the data that they return save in the .ini file. Any information that I manually put in the .ini file will be read correctly with the iniread() function but when I click the save button the info is not saving into the .ini file using the iniwrite() function. I have included the code below and I would appreciate some direction with this issue. Thanks.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("{PAUSE}", "Terminate")

$settings = "Settings.ini"
$section = "User Settings"

$inputvalue1 = IniRead($settings, $section, "Input1", "")
$inputvalue2 = IniRead($settings, $section, "Input2", "")

Func Terminate()
    Exit
EndFunc   ;==>Terminate

$Form1_1 = GUICreate("Test", 494, 392, 232, 145)
$input1 = GUICtrlCreateInput($inputvalue1, 108, 100, 273, 21)
$input2 = GUICtrlCreateInput($inputvalue2, 108, 132, 273, 21)
$Button5 = GUICtrlCreateButton("Browse", 388, 132, 81, 20, $WS_GROUP)
$Button6 = GUICtrlCreateButton("Browse", 388, 100, 81, 20, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Save", 216, 336, 89, 49, BitOR($BS_MULTILINE, $WS_GROUP))
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button2
            IniWrite($settings, $section, "Input1", $location1)
            IniWrite($settings, $section, "Input2", $location2)

            Case $Button6
            $location1 = FileOpenDialog("Choose Location", "", "Exe files (*.exe)")
            GUICtrlSetData($input1, $location1, "")

        Case $Button5
            $location2 = FileOpenDialog("Choose Location", "", "Text files (*.txt)")
            GUICtrlSetData($input2, $location2, "")


    EndSwitch
WEnd
Edited by hornet
Link to comment
Share on other sites

You should declare $location1 and $location2 outside the While loop.

As it is, those two variables are only exist inside the "Case $Button6" and "Case $Button5" code blocks. By the time you want to write them into you ini file, they do not exist.

Edited by omikron48
Link to comment
Share on other sites

Nope - the problem with the script is that the ini file name has no location given whatsoever.

It is enough to change

$settings = @ScriptDir&"\Settings.ini"

and it will work very well.

Always provide a full path or you'll get problems like this one!

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

No worries :blink:

omikron48 gave you a very good idea too, you need to pay attention to such things too because your script will give an error if you didn't select the files but you hit the "Save" button; in that case $location1 and $location2 variables wouldn't exist so the script will exit.

If you follow his advice, that won't happen.

My answer was only adressing your issue ;)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Didn't know that the variables $location1 and $location2 will continue to exist in such a case.

I'm more used to proper programming using variable declarations before usage, like in C or Java.

Opt("MustDeclareVars", 1) is my friend.

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...