Jump to content

writing variables to file and read them on request


daniel02
 Share

Recommended Posts

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

Link to comment
Share on other sites

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 by Zedna
Link to comment
Share on other sites

Hi Zedna,

thanks for your answer. This looks very good but if I try to use it I get an error. :D

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

Link to comment
Share on other sites

$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 by TurionAltec
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...