read ini file help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lew046
Posts: 5
Joined: 15 Mar 2019, 09:55

read ini file help

19 Mar 2019, 03:36

Hi! Please somebody help me
i would like to read an ini file into dropdown lis options like this

the .ini file

Code: Select all

[Seasons]
Summer = {Up}{Right 2}{Down}
Fall = {Up}{Left 1}{Down}
Winter = {Up }{Right 8}{Down}
Spring = {Up}{Right 16}{Down}{Right 8}{Down}
instead of this, i would like to read the season names from the .ini file to put into the dropdownlist
the .ahk file

Code: Select all


Seasons =
(Join|
Summer|
Fall|
Winter|
Spring
)

Gui, Add, DDL, x10 y10 w380 Center vCarNames, %Seasons%
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: read ini file help

19 Mar 2019, 04:06

Try this:

Code: Select all

/*
[Seasons]
Summer = {Up}{Right 2}{Down}
Fall = {Up}{Left 1}{Down}
Winter = {Up }{Right 8}{Down}
Spring = {Up}{Right 16}{Down}{Right 8}{Down}
[]
*/


    Seasons := ""
    IniRead, OutputVar, %A_ScriptFullPath%, Seasons
    for k, v in StrSplit(OutputVar, "`n", "`r")
        Seasons .= StrSplit(v, "=")[1] "|" (A_Index = 1 ? "|" : "")
    Gui, Add, DDL, x10 y10 w380 Center vCarNames, %Seasons%
    Gui, Show

return ; end of auto-execute section

GuiClose:
GuiEscape:
ExitApp
I hope that helps.
lew046
Posts: 5
Joined: 15 Mar 2019, 09:55

Re: read ini file help

19 Mar 2019, 04:09

i found this (it seems to be working)

Code: Select all

OutputVar := IniGetKeys("test.ini", "MySection" , "|")
msgbox, %OutputVar%
ExitApp



;     (¯`·._ (¯`·._  <[Function]>  _.·´¯) _.·´¯)
;-- Retrieves all keys in particular secion of a standard format .ini file --
;         OutputVar := IniGetKeys(Filename, Section [, Delimiter])

IniGetKeys(InputFile, Section , Delimiter="")
{
	;msgbox, OutputVar=%OutputVar% `n InputFile=%InputFile% `n Section=%Section% `n Delimiter=%Delimiter%
	Loop, Read, %InputFile%
	{
		If SectionMatch=1
		{
			If A_LoopReadLine=
				Continue
			StringLeft, SectionCheck , A_LoopReadLine, 1
			If SectionCheck <> [
			{
				StringSplit, KeyArray, A_LoopReadLine , =
				If KEYSlist=
					KEYSlist=%KeyArray1%
				Else
					KEYSlist=%KEYSlist%%Delimiter%%KeyArray1%
			}
			Else
				SectionMatch=
		}
		If A_LoopReadLine=[%Section%]
			SectionMatch=1
	}
	return KEYSlist
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: GEOVAN, Spelth and 119 guests