Ini file help Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Plantim
Posts: 13
Joined: 22 May 2020, 23:56

Ini file help

20 Sep 2021, 08:03

Hello,

I want to :
- my script checks if an ini file exist
- if not, then create one
- if exist, then check if value exist, don't edit it. If value doesn't exist, then create it

Code: Select all

IniRead, active1 , FollowSettings.ini, Personnages, active1
IniWrite, % active1 , FollowSettings.ini, Personnages, active1
IniWrite, % active2 , FollowSettings.ini, Personnages, active2
With the code below, active1 is setting "ERROR" (because value don't exist the first time)
If i don't set "iniRead", it will erase any value evrytime...

I want, for example, checking value, if it find "active1 = %anyvalue%", don't edit it. If Active1 doesn't exist, create it but with empy value

Thank you for help, sorry for bad english
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Ini file help  Topic is solved

20 Sep 2021, 08:40

After you read the value, check to see if it is ERROR. If so, then you can write the new value. An alternative is below.

Code: Select all

ini    := StrReplace(A_ScriptFullPath, ".ahk", ".ini")
active1 = a
active2 = b
section = Personnages
Loop, 2 {
 IniRead ,   active%A_Index%, %ini%, %section%, active%A_Index%, % active%A_Index%
 IniWrite, % active%A_Index%, %ini%, %section%, active%A_Index%
}
MsgBox, 64, Results, active1 = %active1%`nactive2 = %active2%
Adjust as needed. This does not store an empty value, but you could do that if needed. There is typically not much value in doing that.
Plantim
Posts: 13
Joined: 22 May 2020, 23:56

Re: Ini file help

20 Sep 2021, 11:10

Thank you !
I just added %A_Space% after every "IniRead"

Like this

Code: Select all

IniRead, active1 , FollowSettings.ini, Personnages, active1, %A_Space%
Now it works like i wanted !

Thank you very much

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 265 guests