hornet Posted July 5, 2010 Posted July 5, 2010 (edited) 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. expandcollapse popup#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 July 5, 2010 by hornet
omikron48 Posted July 5, 2010 Posted July 5, 2010 (edited) 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 July 5, 2010 by omikron48
somdcomputerguy Posted July 5, 2010 Posted July 5, 2010 Try thisCase $Button2 IniWrite($settings, $section, "Input1", GUICtrlRead($location1)) IniWrite($settings, $section, "Input2", GUICtrlRead($location2))Note where I added the GUICtrlRead function. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
enaiman Posted July 5, 2010 Posted July 5, 2010 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 :)
hornet Posted July 5, 2010 Author Posted July 5, 2010 Thank you so much for the fast replies guys. Enaiman, you hit the nail right on the head. I just changed that one little thing and the issue was resolved. Thanks again. -hornet
enaiman Posted July 5, 2010 Posted July 5, 2010 No worries 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 :)
omikron48 Posted July 5, 2010 Posted July 5, 2010 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.
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