.ini +1 Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

.ini +1

23 Nov 2017, 11:03

How can use a variable to write .ini file? like if previous Key value is 1, then make it 2 next time and increase by 1 everytime, Thanks!
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: .ini +1

23 Nov 2017, 11:46

Hi HIAC,

You can force an expression:

Code: Select all

IniWrite, % var+1, %iniFilePath%, mySection, myKey

Code: Select all

iniFile := A_ScriptDir . "\test_ini.ini" ; use the colon-equal operator, which evaluates an expression and stores the result in a variable, everything that is not enclosed in quotes is supposed to be the name of a variable, a mathematical operation, a function call etc.; the dot is used to concatenate
if not (FileExist(iniFile)) {
FileAppend,
(
[mySection]
myKey=5
), % iniFile, utf-16 ; IniRead an IniWrite rely on functions which support Unicode only in UTF-16 files (if you intend to use cyrillic for example)
}
sleep, 1000

Loop, 5
{
IniRead, outputvar, % iniFile, mySection, myKey
IniWrite, % outputvar+5, % iniFile, mySection, myKey ; *100 for example
Run, notepad %iniFile%,,, PID ; runs notepad and stores its process ID in PID outputvar
WinWait, ahk_pid %PID%
WinWaitClose
}
my scripts
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: .ini +1

23 Nov 2017, 12:29

Thank you very much..
Now I have the problem when KEY contains "[ ]" value will become ERROR and it will write new key instead of overwriting it ( I use variable for key)

Code: Select all

[ABV]
[AA]BB[CC]=1
[AA]BB[CC]=1
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: .ini +1  Topic is solved

23 Nov 2017, 13:07

Actually, brackets are meaningfull using the ini format; you'll have to escape them:

Code: Select all

[ABV]
\[AA\]BB\[CC\]=1
\[AA\]BB\[CC\]=1
; ...
IniRead, outputvar, % iniFile, ABV, \[AA\]BB\[CC\], ERROR
[EDIT] Escaping only the first one should work too.
my scripts
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: .ini +1

23 Nov 2017, 14:39

Solved, thank you

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, Google [Bot], RandomBoy, Rohwedder and 356 guests