simple iniwrite Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LC_1
Posts: 5
Joined: 29 Dec 2021, 03:07

simple iniwrite

Post by LC_1 » 26 Jan 2022, 07:49

Hello everybody,
only a small queston: whats wrong in my code??

Code: Select all

IniRead, string_to, C:\XX\auto_replace.ini, Section1, replace_to
string_to := StrReplace(string_to, "A", "B") 
IniWrite % string_to, C:\XX\auto_replace.ini, Section1, replace_to
no string is writing in ini file.

Thanks

User avatar
boiler
Posts: 16903
Joined: 21 Dec 2014, 02:44

Re: simple iniwrite

Post by boiler » 26 Jan 2022, 08:03

Put this line after the IniRead and before the IniWrite to see what the variable actually contains:

Code: Select all

MsgBox, % string_to

Do you perhaps have a typo in the path to the ini file? Put this at the top of your script (replacing XX as necessary, of course):

Code: Select all

MsgBox, % "Ini file " . (FileExist("C:\XX\auto_replace.ini") ? "found" : "not found")


Can you post the contents of your ini file?

LC_1
Posts: 5
Joined: 29 Dec 2021, 03:07

Re: simple iniwrite

Post by LC_1 » 26 Jan 2022, 08:42

Ini file is correctly read, and replace_to string content is regurarly show in the msgbox. Something wrong in write function.
This is ini file content:

Code: Select all

[Section1]
replace_from=text_from
replace_to=text_to

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: simple iniwrite

Post by BoBo » 26 Jan 2022, 09:20

Code: Select all


/*
[Section1]
replace_to=1AAAAAA2
*/

IniRead, string_to, % A_ScriptName, Section1, replace_to
MsgBox % string_to := StrReplace(string_to, "A", "B") 
IniWrite % string_to, % A_ScriptName, Section1, replace_to
; check your scripts "ini section" for changes, probably you've to "refresh" the open file with pushing F5!

User avatar
boiler
Posts: 16903
Joined: 21 Dec 2014, 02:44

Re: simple iniwrite  Topic is solved

Post by boiler » 26 Jan 2022, 09:23

@LC_1 - What are you expecting to be written to it? You haven’t changed anything in in the string text_to when you’re replacing A with B. The ini file you showed would correctly look the same before and after running your script.

Perhaps you meant to read from replace_from instead of replace_to:

Code: Select all

IniRead, string_to, C:\XX\auto_replace.ini, Section1, replace_from
string_to := StrReplace(string_to, "A", "B") 
IniWrite % string_to, C:\XX\auto_replace.ini, Section1, replace_to

LC_1
Posts: 5
Joined: 29 Dec 2021, 03:07

Re: simple iniwrite

Post by LC_1 » 26 Jan 2022, 12:08

I'm sorry, I was using uncorrect variable name during writing process. :o Thank you all.

Post Reply

Return to “Ask for Help (v1)”