Help with INI READ

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
the1corrupted
Posts: 36
Joined: 25 Jan 2014, 23:01

Help with INI READ

27 Jan 2014, 13:25

Hey, all

Playing around with INI Read (because it would be a pain if I really had to leave all this information hardcoded)

I loop through an array, and try to read the file. The problem is, I don't have any information stored when I create a dump file.

I currently have something like this setup...

Code: Select all

Array["Set1"]:=[]	;	Emtpy sub-array
if (FileExist("resource/config.ini")) {
	;	The following has no problems:
	IniRead, set1, resource/config.ini, DATA SET 1, all, false
	Loop, Parse, prefixes, |
	{
		Array["Set1"][A_Index]:=A_LoopField
	}
	;	The following does not appear to store information...
	for index in Array["Set1"]
	{
		;	GET INFORMATION FROM CONFIG.INI FOR EACH PREFIX
		prefix:=Array["Set1"][index]
		IniRead, name, SET 1 NAME, %prefix%, false
		Array["name"][prefix]:=name
	}
}

DumpFile:="dump\DEBUG_DUMP.txt"
if (FileExist(DumpFile)) {
	FileDelete, %DumpFile%
}
AppendString:="DEBUG DUMP"
for index in Array["Set1"] {
	prefix:=Array["Set1"][index]
	AppendString.="`r`nPREFIX: " . prefix
	AppendString.="`r`nNAME(" . prefix . ")`t`t=`t" . Array["name"][prefix]
	AppendString.="`r`n"
}
FileAppend, %AppendString%, %DumpFile%
MsgBox, Created dump file: %DumpFile%
INI File has the following:

Code: Select all

[DATA SET 1]
all=PRE1|PRE2|PRE3|PRE4
[SET 1 NAME]
PRE1=PREFIX 1
PRE2=PREFIX 2
PRE3=PREFIX 3
PRE4=PREFIX 4
Automating work is twice as much fun
User avatar
LazyMan
Posts: 26
Joined: 14 Jan 2014, 00:22
Location: peering out from behind my favorite rock

Re: Help with INI READ

27 Jan 2014, 14:09

Seems like, in that section of code with the assertion,
The following has no problems:
you need something like:

Code: Select all

prefixes := set1
between your IniRead and Loop.

(If there are other problems, post again; I quit looking after that.)
User avatar
the1corrupted
Posts: 36
Joined: 25 Jan 2014, 23:01

Re: Help with INI READ

27 Jan 2014, 15:07

LazyMan wrote:Seems like, in that section of code with the assertion,
The following has no problems:
you need something like:

Code: Select all

prefixes := set1
between your IniRead and Loop.

(If there are other problems, post again; I quit looking after that.)
I caught that error. Recompiled, tested again and I give up on trying to simplify this anymore. I GIVE UP I TELL YOU!!

(Forgive me for the copious amounts of code, but I'm lazy and copy/pasted the entire thing)

I think I'm calling a variable wrong, but I'm not sure how/where and/or why this isn't working

Instead, I'll post the relevent bits of code...[/strike]

I was an idiot and fixed the problem. I forgot "FileName" with my IniRead calls.
Automating work is twice as much fun
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Help with INI READ

27 Jan 2014, 16:12

Missing Filename parameter?

Code: Select all

            IniRead, name, RMA NAME, %prefix%, false
            IniRead, addr, RMA ADDRESS, %prefix%, false
            IniRead, facility, RMA FACILITY, %prefix%, false
Edit: I see you found it while I was posting :)
User avatar
the1corrupted
Posts: 36
Joined: 25 Jan 2014, 23:01

Re: Help with INI READ

27 Jan 2014, 16:34

kon wrote:Missing Filename parameter?

Code: Select all

            IniRead, name, RMA NAME, %prefix%, false
            IniRead, addr, RMA ADDRESS, %prefix%, false
            IniRead, facility, RMA FACILITY, %prefix%, false
Edit: I see you found it while I was posting :)
Yup, but now I have a new (and very strange problem)...

This is not giving me a message box for each variable assignment....

I broke it down and put the "name" variable in a message box in relation to the prefix, and THAT was posting OK. I got a message box with each prefix and name. But I try to fold it into the array, and it gets lost somehow...

Code: Select all

for index in RMA["prefix"]
	{
	;	GET INFORMATION FROM CONFIG.INI FOR EACH PREFIX
	prefix:=RMA["prefix"][index]
	IniRead, name, resource/config.ini, RMA NAME, %prefix%
	IniRead, addr, resource/config.ini, RMA ADDRESS, %prefix%
	IniRead, facility, resource/config.ini, RMA FACILITY, %prefix%
	RMA["name"][prefix]:=name
	if (RMA["name"][prefix]) {	;	Try with if(name), and this snippet works..
		MsgBox, NAME: %name%
	}
	RMA["addr"][prefix]:=addr
	RMA["facility"][prefix]:=facility
}
Automating work is twice as much fun
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Help with INI READ

27 Jan 2014, 17:20

If I am understanding correctly, you have a different array for Name, addr, and facility? Are you initializing them at some point?

Code: Select all

RMA := {}
RMA["prefix"] := ["Pre1", "Pre2"]
RMA["name"] := {}
RMA["addr"] := {}
RMA["facility"] := {}


for index, val in RMA["prefix"]
    {
    ;   GET INFORMATION FROM CONFIG.INI FOR EACH PREFIX
    MsgBox, % "prefix(" val "): " prefix:=RMA["prefix"][index]
	
    ;IniRead, name, resource/config.ini, RMA NAME, %prefix%
	name := "name" index
    ;IniRead, addr, resource/config.ini, RMA ADDRESS, %prefix%
	addr := "addr" index
    ;IniRead, facility, resource/config.ini, RMA FACILITY, %prefix%
	facility := "fac" index
	
	RMA["name"][prefix]:=name
    MsgBox, % "Name(" val "): " RMA["name"][prefix]

	RMA["addr"][prefix]:=addr
    MsgBox, % "addr(" val "): " RMA["addr"][prefix]
	
	RMA["facility"][prefix]:=facility
    MsgBox, % "facility(" val "): " RMA["facility"][prefix]
}

MsgBox, % RMA["facility"]["Pre2"]
User avatar
the1corrupted
Posts: 36
Joined: 25 Jan 2014, 23:01

Re: Help with INI READ

27 Jan 2014, 20:30

Not so specifically. I create the empty RMA object (RMA:={})

I had been able to do this previously, but I was using an old version of AHK_L (from http://www.autohotkey.com) but I updated to the latest (published here on AHKScript) and that's when everything got a little fuzzy.

So just for grins, I added object initialization calls before the for {} loop. And it worked.

Thanks for all the help guys!

Final Result:

Code: Select all

RMA["name"]:={}
RMA["addr"]:={}
RMA["facility"]:={}
for index in RMA["prefix"]
{
	;	GET INFORMATION FROM CONFIG.INI FOR EACH PREFIX
	prefix:=RMA["prefix"][index]
	IniRead, facName, resource/config.ini, RMA NAME, %prefix%
	IniRead, addr, resource/config.ini, RMA ADDRESS, %prefix%
	IniRead, facility, resource/config.ini, RMA FACILITY, %prefix%
	RMA["name"][RMA["prefix"][index]]:=facName
	RMA["addr"][prefix]:=addr
	RMA["facility"][prefix]:=facility
}
Automating work is twice as much fun
lexikos
Posts: 9635
Joined: 30 Sep 2013, 04:07
Contact:

Re: Help with INI READ

27 Jan 2014, 21:47

the1corrupted wrote:I had been able to do this previously, but I was using an old version of AHK_L (from http://www.autohotkey.com) but I updated to the latest (published here on AHKScript) and that's when everything got a little fuzzy.
RMA := {}, RMA["name"][prefix]:=name would never have worked. However, you can do RMA["name", prefix]:=name as per Arrays of Arrays.

Also, RMA.name[prefix]:=name is equivalent to RMA["name", prefix]:=name but is arguably more readable.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 191 guests