【问题标题】:Reading INI file is not working using IniRead in AHK在 AHK 中使用 IniRead 读取 INI 文件不起作用
【发布时间】:2015-07-08 21:31:39
【问题描述】:

我正在尝试读取 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

感谢任何指导。

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    正如您在MsgBox 中所做的那样,您必须用% 百分号将变量括起来。

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

    因此,您的 iniread 将如下所示:

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

    如需更多详细信息,请访问http://ahkscript.org/docs/Variables.htm。虽然我没有看到任何关于在命令中使用变量的信息

    【讨论】:

    • 我在这里很困惑。为什么%IniFileName% 会被视为变量,而Value 不是变量?
    • 那是因为您必须密切关注文档。 @iniread,关于OutputVar(这里:value)它说:“存储检索值的变量的名称”。另一方面,filename 应该是“.ini 文件的名称”。标记差异,如我上面的回答中所述。
    猜你喜欢
    • 1970-01-01
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 2013-08-02
    • 1970-01-01
    • 1970-01-01
    • 2017-10-20
    相关资源
    最近更新 更多