Jump to content
Sign in to follow this  
blessthefall

Want to save variables for use in another script

Recommended Posts

blessthefall

Okay, so I'm going to try to explain this as well as can:

I want to have a script where, using a GUI window and various inputs, I can save variables into another file to be used by other scripts. See example below for my lousy attempt at making an example of my intended application :P

;;;;;;;;;;;Script.au3;;;;;;;;;;;

#include <GUIConstants.au3>

#include <variables.au3>

;inputs

;formulas

;loops

;other random stuff

;after everything is said and done, I'll have a set of 2 or more variables

$variable_a = 666

$variable_b = 777

;I want to save/update these 2 variables (and nothing else) into "Variables.au3" to be recalled by this and other scripts

;;;;;;;;;;;Variables.au3;;;;;;;;;;;

$variable_a = 0

$variable_b = 0

Share this post


Link to post
Share on other sites
Maxisking

Cant do this. unless you use filewriteline()

I think :S

Share this post


Link to post
Share on other sites
blessthefall

Not familiar with FileWriteLine ()

that may be what i'm looking for, will look into it in a second.

Share this post


Link to post
Share on other sites
blessthefall

Okay, so with some searching and some testing I found a way to get the results I want, but not necessarily by the method I want.

#include <File.au3>

FileDelete ( "variables.au3" ) ;deletes existing variables.au3

_FileCreate ("variables.au3") ;creates new "blank" variables.au3

$file = FileOpen("variables.au3", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "$variable_a = 666" & @CRLF) ;writes new value to line one

FileWrite($file, "$variable_b = 777") ;writes new value to line two

FileClose($file)

Does anyone have any suggestions for a more effective method?

Share this post


Link to post
Share on other sites
autoitter

Maybe you could use INI files. You can write a variables with the IniWrite function.

IniWrite(@ScriptDir & "\MyVars.ini", "Variables", "variable_a", $variable_a)

IniWrite(@ScriptDir & "\MyVars.ini", "Variables", "variable_b", $variable_:P

Share this post


Link to post
Share on other sites
blessthefall

Maybe you could use INI files. You can write a variables with the IniWrite function.

IniWrite(@ScriptDir & "\MyVars.ini", "Variables", "variable_a", $variable_a)

IniWrite(@ScriptDir & "\MyVars.ini", "Variables", "variable_b", $variable_:P

I love you

Share this post


Link to post
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
Sign in to follow this  

×