Theo Posted October 13, 2009 Share Posted October 13, 2009 (edited) Hey all, I need a bit of help here. I have a Gui that writes a bunch of variables to a file. I then want the master script to import those variables. The variables are written one per line in the style: $variable = "value" I first tried using a #include "GuiVars.au3", but it appears that autoit wants to read in all the includes at the beginning of the script no matter where they are located in the script. Then I moved to this: Call( "_importVars" ) ; Get the variables created. Call ( "_Rename", $hostname ) ;pass the new hostname to the rename function Func _importVars() $file = FileOpen("C:\temp\2008_followUp\guiVars.au3", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open guivars.au3 file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop Global $line ; Declare each var in GuiVars.aur as a global variable ; debug MsgBox(1, "Variable", "Current variable is: " & $line) Wend FileClose($file) EndFunc Unfortunaely, the line "Global $line" doesn not seem to be creating global variables because the next call function call ( "_Rename", $hostname ) ;pass the new hostname to the rename function errors out telling me I am using an undeclared variable. My debug statement says the variable should be getting declared correctly. Any thoughts? Is there a better way to import variables? -kp Edited October 13, 2009 by Theo Systems AdministratorSiemens: Windows Server SupportFly Fisher, Table Tennis Junkie, and Struggling Coder Link to comment Share on other sites More sharing options...
omikron48 Posted October 13, 2009 Share Posted October 13, 2009 (edited) Global $line This declares a global variable, $line. I think what you're looking for is Assign or Eval functions. Check the help file. Edited October 13, 2009 by omikron48 Link to comment Share on other sites More sharing options...
FuryCell Posted October 13, 2009 Share Posted October 13, 2009 (edited) This method works. It assumes the file is formatted without quotes however but that can be changed. Call( "_importVars" ) ; Get the variables created. Func _importVars() $file = FileOpen("guivars.au3", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open guivars.au3 file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $Split=StringSplit($Line,"=") Assign(StringReplace($Split[1],"$",""),$Split[2],2) Wend FileClose($file) EndFunc And here is an example GUIVars.au3 $Var1=A $Var2=B Edited October 13, 2009 by P5ych0Gigabyte HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
Theo Posted October 13, 2009 Author Share Posted October 13, 2009 I see what is happening. I am declaring a Global variable called $line, rather than declaring Global <value of variable $line> ....how to fix...hmmmm Systems AdministratorSiemens: Windows Server SupportFly Fisher, Table Tennis Junkie, and Struggling Coder Link to comment Share on other sites More sharing options...
FuryCell Posted October 13, 2009 Share Posted October 13, 2009 I see what is happening. I am declaring a Global variable called $line, rather than declaring Global <value of variable $line>....how to fix...hmmmmUse assign or execute. Did you try my example? HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
Theo Posted October 13, 2009 Author Share Posted October 13, 2009 I can also just declare the variable Global first and then assign the value. sigh, sometimes I am just slow. thanks for your input as well. I have another place I can use your example so your time is not wasted! Systems AdministratorSiemens: Windows Server SupportFly Fisher, Table Tennis Junkie, and Struggling Coder Link to comment Share on other sites More sharing options...
omikron48 Posted October 13, 2009 Share Posted October 13, 2009 (edited) Or if you don't store too much information, you can just use IniWrite and IniRead instead. Edited October 13, 2009 by omikron48 Link to comment Share on other sites More sharing options...
Theo Posted January 11, 2010 Author Share Posted January 11, 2010 Thanks, I ended up using iniWrite, which with the addition of _StringEncrypt()for password data worked perfectly. Systems AdministratorSiemens: Windows Server SupportFly Fisher, Table Tennis Junkie, and Struggling Coder Link to comment Share on other sites More sharing options...
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