Need help with reading INI file into array variables.
Posted: 02 Jun 2018, 09:36
For whatever reason (not enough coffee?), I just can not seem to grasp the concept of reading in an .ini file to arrays for use by variable[indexnum] in other parts of my script.
I know that a .ini file is supposed to be set up thus:
[SectionName]
Key=Value
And I know that an array has to be setup thus:
global SectionArray := []
global KeyArray := []
But what I can't seem to grasp is how to read and parse the file so that it gives me the 'variable[indexnum]' structure.
I.E. SectionArray[1] is expected to contain Event1, and SectionArray[2] is expected to contain Event2, etc.
KeyArray.Date[1] is expected to contain 2018.06.06, and KeyArray.Date[2] is expected to contain 2018.06.07, etc.
KeyArray.Speaker[1] is expected to contain Guest 1, etc.... you get my drift?
When an event is done, I need to write back to the file on the Completed key "Yes" replacing the "No" so it doesn't get processed in the next file read.
So, am I wrong to expect those variables to be filled that way with a parsing of an INI file, or am I just completely wrong?
Event.ini is written in the following fashion...
My code is so messed up now trying all kinds of different things, I don't even know what's right, what needs to be changed, and what needs to be deleted.
I'm really hoping someone here smarter than I can help me out. I've got a major event coming up this next week that requires some AHK finesse and automation.
I know that a .ini file is supposed to be set up thus:
[SectionName]
Key=Value
And I know that an array has to be setup thus:
global SectionArray := []
global KeyArray := []
But what I can't seem to grasp is how to read and parse the file so that it gives me the 'variable[indexnum]' structure.
I.E. SectionArray[1] is expected to contain Event1, and SectionArray[2] is expected to contain Event2, etc.
KeyArray.Date[1] is expected to contain 2018.06.06, and KeyArray.Date[2] is expected to contain 2018.06.07, etc.
KeyArray.Speaker[1] is expected to contain Guest 1, etc.... you get my drift?
When an event is done, I need to write back to the file on the Completed key "Yes" replacing the "No" so it doesn't get processed in the next file read.
So, am I wrong to expect those variables to be filled that way with a parsing of an INI file, or am I just completely wrong?
Event.ini is written in the following fashion...
Code: Select all
[Event1]
Date=2018.06.06
Speaker=Guest 1
Title=TBD
StartTime=18:55
EndTime=19:30
M1=19:00
M2=19:29
Mic=22
MailToList=address1@someplace.com,address2@anotherplace.org,address3@whoknows.net
Completed=No
[Event2]
Date=2018.06.07
Speaker=Guest 2
Title=TBD
StartTime=19:30
EndTime=20:00
M1=19:31
M2=19:59
Mic=10
MailToList=address22@home.net,address23@web.com
Completed=No
[Event3]
Date=2018.06.07
Speaker=Guest 5
Title=TBD
StartTime=15:00
EndTime=20:00
M1=16:31
M2=19:59
Mic=10,12,14,29,30,31,32
MailToList=address52@homeboy.net,address14@someplaceontheweb.com
Completed=No
...
[Event100]
Date=2018.06.012
Speaker=Guest 15
Title=TBD
StartTime=9:00
EndTime=11:00
M1=9:11
M2=10:49
Mic=11,12,13,14,15,16,17,18,29,30,31,32
MailToList=address4052@youth.net,address300@someplaceontheweb23.com
Completed=No
Code: Select all
global DSYCEvent := ["Section", "Date", "Speaker", "Title", "StartTime", "EndTime", "M1", "M2"]
global EventSections := {}
global reaperEventDate := []
global reaperEventSpeaker := []
global reaperEventTitle := []
global reaperEventStartTime := []
global reaperEventEndTime := []
global reaperEventM1Time := []
global reaperEventM2Time := []
...
readIniFile("Event.ini")
ExitApp
readIniFile(IniFile) ;
{
SectionCount := 0
IniRead, OutputVar, %IniFile%
MsgBox, Read in %OutputVar%
/* Loop Parse, OutputVar, `n
{
Section := A_LoopField
MsgBox Section %Section%
;IniRead, keys,%IniFile%, % Section
;MsgBox, Keys: %keys%
;IniRead, reaperEventDate[%SectionCount%], %IniFile%, % Section, Date, %A_Space% ; results in an error
;IniRead, reaperEventSpeaker, %IniFile%, % Section, Speaker, %A_Space%
;IniRead, reaperEventTitle, %IniFile%, % Section, Title, %A_Space%
;IniRead, reaperEventStartTime, %IniFile%, % Section, StartTime, %A_Space%
;IniRead, reaperEventEndTime, %IniFile%, % Section, EndTime, %A_Space%
;IniRead, reaperEventM1Time, %IniFile%, % Section, M1, %A_Space%
;IniRead, reaperEventM2Time, %IniFile%, % Section, M2, %A_Space%
;IniRead, reaperEventMic, %IniFile%, % Section, Mic, %A_Space%
;I am so lost and confused now.
SectionCount +=1
}
*/
return
}