daniel02 Posted September 25, 2009 Posted September 25, 2009 Hi, I would like to write some variables to a file and read them on the next start if wished. I thought i just use iniwrite and iniread or iniwritesection and inireadsesction but it does not seem to work like I want to have it. The goal is to just read all the variables again so they are useable with the same variable names: I wrote them with: IniWriteSection(@ScriptDir & "\test.ini", "Variables", "posxy" & $posx[0] , $pos[1]) I tried to read them with: If FileExists(@ScriptDir & "\test.ini") Then $answer = MsgBox(4, "Test", "There is an test.ini file use it?") If $answer = 6 Then IniReadSection(@ScriptDir & "\test.ini", "Variables") MsgBox(4096, "Result", $posx[0]) EndIf EndIf But it says the variable is not delcared? Can someone help me with this. Thanks Daniel
Zedna Posted September 25, 2009 Posted September 25, 2009 (edited) Something like this: $pos = MouseGetPos() IniWriteSection(@ScriptDir & "\test.ini", "Variables", "posx=" & $pos[0] & @LF & 'posy=' & $pos[1]) If FileExists(@ScriptDir & "\test.ini") Then $answer = MsgBox(4, "Test", "There is an test.ini file use it?") If $answer = 6 Then $var = IniReadSection(@ScriptDir & "\test.ini", "Variables") For $i = 1 To $var[0][0] MsgBox(4096, "Result", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next EndIf EndIf Also look at examples for IniWriteSection,IniReadSection in Autoit's helpfile. Edited September 25, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
daniel02 Posted September 25, 2009 Author Posted September 25, 2009 Hi Zedna, thanks for your answer. This looks very good but if I try to use it I get an error. : ==> Subscript used with non-Array variable.: For $i = 1 To $var[0][0] For $i = 1 To $var^ ERROR And how can I than use again the $pos variable with the two values? Thanks in advance. Daniel Something like this: $pos = MouseGetPos() IniWriteSection(@ScriptDir & "\test.ini", "Variables", "posx=" & $pos[0] & @LF & 'posy=' & $pos[1]) If FileExists(@ScriptDir & "\test.ini") Then $answer = MsgBox(4, "Test", "There is an test.ini file use it?") If $answer = 6 Then $var = IniReadSection(@ScriptDir & "\test.ini", "Variables") For $i = 1 To $var[0][0] MsgBox(4096, "Result", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next EndIf EndIf Also look at examples for IniWriteSection,IniReadSection in Autoit's helpfile.
TurionAltec Posted September 25, 2009 Posted September 25, 2009 (edited) $pos = MouseGetPos() IniWriteSection(@ScriptDir & "\test.ini", "Variables", "posx=" & $pos[0] & @LF & 'posy=' & $pos[1]) If FileExists(@ScriptDir & "\test.ini") Then $answer = MsgBox(4, "Test", "There is an test.ini file use it?") If $answer = 6 Then $var = IniReadSection(@ScriptDir & "\test.ini", "Variables") For $i = 0 To Ubound($var,1) MsgBox(4096, "Result", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next EndIf EndIf Changed this line: For $i = 0 To Ubound($var,1) Edited September 25, 2009 by TurionAltec
TurionAltec Posted September 25, 2009 Posted September 25, 2009 Try this for writing and reading respectively. ;Writing IniWrite(@ScriptDir & "\test.ini","Variables","posx",$pos[0] IniWrite(@ScriptDir & "\test.ini","Variables","posy",$pos[1] ;Reading Dim $pos[2] $pos[0]=IniRead(@ScriptDir & "\test.ini","Variables","posx") $pos[1]=IniRead(@ScriptDir & "\test.ini","Variables","posy")
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