Friedel2k Posted August 19, 2021 Posted August 19, 2021 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!
Zedna Posted August 19, 2021 Posted August 19, 2021 Look at IniReadSection() in helpfile. Resources UDF ResourcesEx UDF AutoIt Forum Search
Friedel2k Posted August 20, 2021 Author Posted August 20, 2021 Thank u ! I got it. Please one more question. Now I got the data in an array, but how to get these data into vars? Or to update existing vars? Thank you!
Zedna Posted August 20, 2021 Posted August 20, 2021 (edited) #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 August 20, 2021 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
Friedel2k Posted August 20, 2021 Author Posted August 20, 2021 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.
Nine Posted August 20, 2021 Posted August 20, 2021 You cannot have a variable starting with 2 $. You would need to remove the first $ from the array before creating the variables (or simply remove them from ini file). “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Zedna Posted August 20, 2021 Posted August 20, 2021 (edited) Thanks Nine for good pointing! For this INI file: Quote [printer]pool_1=1pool_2=2pool_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 August 20, 2021 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
Friedel2k Posted August 24, 2021 Author Posted August 24, 2021 Thx a lot! Thats it! Works fine for me. Thank you all!
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