Search code examples
autohotkeyini

Autohotkey IniRead pass section name as variable in AHK


I have the following tiny .ini file:

["General"]
"runs"="3"

When using this code to read the file, I get a message box stating the correct number of runs

path := A_ScriptDir "\setup.ini"
IniRead, temp, % path, "General", "runs"
MsgBox, % temp

When I try to pass General as a variable, the message box outputs "ERROR"

path := A_ScriptDir "\setup.ini"
iniSection := "General"
IniRead, temp, % path, % iniSection, "runs"
MsgBox, % temp

I tried enclosing the variables in %-signs, instead of just prefixing them, but it does not make a difference.

Any help is appreciated!


Solution

  • Variable names in an expression are not enclosed in percent signs. Consequently, literal strings must be enclosed in double quotes to distinguish them from variables.

    To include an actual quote-character inside a literal string, specify two consecutive quotes:

    iniSection := """General"""