Jump to content

IniRead --> All Keys as a variable + its value


Recommended Posts

Dear all,

i just can not solve it. I hope u can give me a right tip.

I just want to import a ini file, for example:

[printer]
$pool_1=1
$pool_2=2
$pool_3=3

 

with the function IniRead and I want to use direct $pool_1 as var, and the var should have the value 1

and of course has the ini file later n entrys for N vars. I have tryed evey help / refference / forum, but Iam just not able to get it. Thanks for feedback!

 

 

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $pom

$var = IniReadSection('opt.ini','printer')
If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
;~      MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
        $pom &= "Key"&$i&": " & $var[$i][0] & " Value"&$i&": " & $var[$i][1] & @CRLF
        Assign($var[$i][0], $var[$i][1]) ; create variable
    Next
EndIf

MsgBox(4096, "IniReadSection array", $pom)
MsgBox(4096, "Variables", "$pool_1: " & Eval('$pool_1') & @CRLF & "$pool_2: " & Eval('$pool_2') & @CRLF & "$pool_3: " & Eval('$pool_3'))

 

Edited by Zedna
Link to comment
Share on other sites

Thank you, but it seems not that this will generate var´s. And also not the values for the var´s. If I "ask" autoit vor the vars and or var / result there are no values.

Or is there a other option to import vars from a text file with there values? Thank you.

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Thanks Nine for good pointing!

For this INI file:

Quote

[printer]
pool_1=1
pool_2=2
pool_3=3

Works This my script:

Note that you have to disable Au3Check if you have $ + name of dynamic variable mentioned directly in script (my last line)

#AutoIt3Wrapper_Run_AU3Check=n

Dim $pom

$var = IniReadSection('opt.ini','printer')
If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
        $pom &= "Key"&$i&": " & $var[$i][0] & " Value"&$i&": " & $var[$i][1] & @CRLF
        Assign($var[$i][0], $var[$i][1])  ; create variable
    Next
EndIf

MsgBox(4096, "IniReadSection array", $pom)
MsgBox(4096, "Variables Eval", "$pool_1: " & Eval('pool_1') & @CRLF & "$pool_2: " & Eval('pool_2') & @CRLF & "$pool_3: " & Eval('pool_3'))
MsgBox(4096, "Variables Direct", "$pool_1: " & $pool_1 & @CRLF & "$pool_2: " & $pool_2 & @CRLF & "$pool_3: " & $pool_3) ; <-- Au3Check must be disabled

 

Edited by Zedna
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...