在AHK中使用IniRead读取INI文件无效

时间:2015-07-08 05:25:35

标签: autohotkey

我正在尝试读取INI文件并使用AHK从中获取值。但是,读取不成功,我每次都会从呼叫中获得default值。

以下是我使用的代码: -

ReadIniFile(IniFileName, SectionName, KeyName,ByRef Value)
{
   If FileExist(IniFileName)
   { 
     MsgBox File found ; this comes
   }

   IniRead, Value, IniFileName, SectionName, KeyName , Default
   MsgBox %Value% %IniFileName% %KeyName% %SectionName% ; Value comes as 'Default'
 }

输出结果为: -

Default C:\Users\barmans\Desktop\ECU.h ININame GeneralSettings

函数调用是:

ReadIniFile(HeaderFileName, "GeneralSettings", "ININame",    AutoTestScript)

INI的格式为: -

[GeneralSettings]
ECU=ABS8_B
ININame=ABS8_B_Test.ini
KBDiagPath=C:\KBApps\Knorr-Bremse\KB Diag
RunCount=0
[LogSettings]
LogFileName=ABS8_B_Report.log
TraceLevel=1

感谢任何指导。

1 个答案:

答案 0 :(得分:1)

正如您在MsgBox中所做的那样,您必须使用%百分号来包含变量。

如果文档告诉您说明"名称","值"或类似的东西,你需要一个实际的字符串或整数。除此之外,有时您会被要求说明变量名称",在这种情况下,您显然不能使用% - 就像在函数调用中一样。

所以,你的iniread看起来像:

IniRead, Value, %IniFileName%, %SectionName%, %KeyName%, Default

有关详细信息,请访问http://ahkscript.org/docs/Variables.htm。我没有在命令中看到有关变量使用的任何内容