help with a function to read all ini variables

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

help with a function to read all ini variables

Post by ibieel » 16 Dec 2022, 16:37

hey guys, could you help me to read all the variables from an .ini file
the variables are not always the same, it can change, but the section is always the same.
Is there any script/function that I can read all the variables of a section in ini file?

INI EXAMPLE:

Code: Select all

[Section1]
Var11=test
Var13=testq
Var00=testw
Var098=testr

[Section2]
Var99=testt
Var19=testy
Var10=testuy
Var65=tesjj
Var1=testb
User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: help with a function to read all ini variables

Post by flyingDman » 16 Dec 2022, 16:57

Try:

Code: Select all

iniread, oVar, test43210.ini, section1
for x,y in strsplit(oVar,"`n")
	{
	tmp1 := strsplit(y,"=").1
	tmp2 := strsplit(y,"=").2
	%tmp1% := tmp2
	}

msgbox % var13
14.3 & 1.3.7
User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: help with a function to read all ini variables

Post by flyingDman » 16 Dec 2022, 17:17

To extract all variables from all sections, try:

Code: Select all

fileread, oVar, test43210.ini
for x,y in strsplit(oVar,"`n","`r")
		{
		tmp1 := strsplit(y,"=","`n`r").1
		tmp2 := strsplit(y,"=","`n`r").2
		(tmp1) && !instr(y,"[") && %tmp1% := tmp2
		}

msgbox % var13
14.3 & 1.3.7
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: help with a function to read all ini variables

Post by HiSoKa » 16 Dec 2022, 17:29

Thanks flyingDman, But when i try it get this error,
error.png
error.png (36.71 KiB) Viewed 824 times
Is the problem in the code?,
Or the problem in the way I run it, or in the my INI file?
User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: help with a function to read all ini variables

Post by flyingDman » 16 Dec 2022, 17:49

I guess it is how the .ini file is formatted. Could you post it?
14.3 & 1.3.7
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: help with a function to read all ini variables

Post by HiSoKa » 16 Dec 2022, 18:02

[File 1]
Main Section = Programming
Secound Section = Ask For Help

[File 2]
Main Section = Programming
Secound Section = Functions

[File 3]
Main Section = Programming
Secound Section = Classes

[File 4]
Main Section = Programming
Secound Section = Misc

[File 5]
Main Section = Design
Secound Section = Photoshop

[File 6]
Main Section = Design
Secound Section = After Effect


and this is the code :

Code: Select all

MyData_INI             := "D:\New folder (5)\MY Data.ini"

fileread, oVar, %MyData_INI%
for x,y in strsplit(oVar,"`n","`r")
		{
		tmp1 := strsplit(y,"=","`n`r").1
		tmp2 := strsplit(y,"=","`n`r").2
		(tmp1) && !instr(y,"[") && %tmp1% := tmp2
		}

msgbox % var13
User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: help with a function to read all ini variables

Post by flyingDman » 16 Dec 2022, 18:04

A variable cannot have spaces....
14.3 & 1.3.7
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: help with a function to read all ini variables

Post by HiSoKa » 16 Dec 2022, 18:08

W̶h̶i̶c̶h̶ ̶v̶a̶r̶i̶a̶b̶l̶e̶ ̶d̶o̶ ̶y̶o̶u̶ ̶m̶e̶a̶n̶?̶
Edit:
Sorry, flyingDman, now I understand the code you posted :oops: , which is to parse the INI file and make the keys and values as variables,
And then call them when needed..
I delete the spaces and now everything is working fine..
Thank you for the great code...
Last edited by HiSoKa on 16 Dec 2022, 18:16, edited 1 time in total.
User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

Re: help with a function to read all ini variables

Post by ibieel » 21 Dec 2022, 15:17

flyingDman wrote:
16 Dec 2022, 16:57
Try:

Code: Select all

iniread, oVar, test43210.ini, section1
for x,y in strsplit(oVar,"`n")
	{
	tmp1 := strsplit(y,"=").1
	tmp2 := strsplit(y,"=").2
	%tmp1% := tmp2
	}

msgbox % var13
it seems that iniRead has a limit of 65720 characters, is there a way to increase this limit?
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: help with a function to read all ini variables

Post by wetware05 » 21 Dec 2022, 16:02

ibieel wrote:
21 Dec 2022, 15:17
flyingDman wrote:
16 Dec 2022, 16:57
Try:

Code: Select all

iniread, oVar, test43210.ini, section1
for x,y in strsplit(oVar,"`n")
	{
	tmp1 := strsplit(y,"=").1
	tmp2 := strsplit(y,"=").2
	%tmp1% := tmp2
	}

msgbox % var13
it seems that iniRead has a limit of 65720 characters, is there a way to increase this limit?
Hi, ibieel.

Variables that are read in an .ini file are usually because they have been written to by the script itself. Refers to states of variables that you want to retrieve in another session or execution of the script. For example, in a music player, what song was playing when you closed the program to play it again. I think that this is not what you want or need, otherwise there would not be so many variables.
User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

Re: help with a function to read all ini variables

Post by ibieel » 21 Dec 2022, 20:07

wetware05 wrote:
21 Dec 2022, 16:02
ibieel wrote:
21 Dec 2022, 15:17
flyingDman wrote:
16 Dec 2022, 16:57
Try:

Code: Select all

iniread, oVar, test43210.ini, section1
for x,y in strsplit(oVar,"`n")
	{
	tmp1 := strsplit(y,"=").1
	tmp2 := strsplit(y,"=").2
	%tmp1% := tmp2
	}

msgbox % var13
it seems that iniRead has a limit of 65720 characters, is there a way to increase this limit?
Hi, ibieel.

Variables that are read in an .ini file are usually because they have been written to by the script itself. Refers to states of variables that you want to retrieve in another session or execution of the script. For example, in a music player, what song was playing when you closed the program to play it again. I think that this is not what you want or need, otherwise there would not be so many variables.
it doesn't have many variables, about 200... but there are many characters in each variable.
what would you advise me to do to record/retrieve these variables with many characters?
maybe a database? how can i link a database with autohotkey?
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: help with a function to read all ini variables

Post by wetware05 » 22 Dec 2022, 05:40

hi ibieel

There are people more expert than me to answer you. I think you should open another thread where you have to answer yourself if you want to have all that data present in the script, or if you can read it from the file when a piece of data is needed (one or more at a time).

A database does the last thing I say: read specific data, in specific situations, from a database file. That same data can be a txt or csv file.

Another question is to create an array or pseudo-array, which will remain in memory.
Post Reply

Return to “Ask for Help (v1)”