It will read all the variables stored in a ini and makes them known to the calling script by creating them under fly.
Useful because it can save many lines in a script.
Might be useful to others...
Code: Select all
ReadIni(InputFile) { ; InputFile should be full path or var containing path to the ini. ReadIni("z:\IniFile.ini")
local TmpVar ; Set TmpVar local to the function. All variables created by references name
; will be global to the calling script.
Loop, parse, % FileOpen(InputFile, 0).read(), `n, `r ; Use FileOpen() and parse the fileObject directly in to the loop using read() method.
{ ; A_LoopField will contain the 'current' line in the ini file.
if (((InStr(A_LoopField, "[")) = 1 ? 1) || ((InStr(A_LoopField, "`;")) = 1 ? 1) || !A_LoopField) ; Comments and Sections Should start on the first
Continue ; position on each line found in the ini file!
TmpVar := InStr(SubStr(A_LoopField, 1, InStr(A_LoopField, "=")-1), ";" ; Assign variable name to TmpVar. The name will be referenced below.
%TmpVar% := SubStr(A_LoopField, InStr(A_LoopField, "=")+1) ; Assign the value for the variable name, referenced in %TmpVar%.
} ; If TmpVar contains string GuiX, then the script will read '%TmpVar% := ...'
} ; as it is written 'GuiX := ...'
; by Megnatar.