Ini Help

Get help with using AutoHotkey and its commands and hotkeys
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

Ini Help

16 Aug 2017, 15:57

What I do is I reopen claims to make payments, but sometimes I have to wait for authorization so the claims stay open. I created a database of reopened claims so I can view them every day and see if my payments were authorized so I may reclose those claims.

First question:
For IniDelete and IniRead, Is there a way to delete the section when the key is empty?

Second question:
For IniRead, is it possible to append the .ini by date?

Code: Select all

Adjuster := "Company1"
CloseReason := "Settlement agreed"
Claim := "2017TX023023"
Date := "8/16/17"

IniWrite, %CloseReason%=%Date%, Reopened_Claims.ini, %Adjuster%, %Claim%

IniRead, Company, Reopened_Claims.ini, %Adjuster%
MsgBox % Company

IniDelete, Reopened_Claims.ini, %Adjuster%, %Claim%
IniRead, Reopened_Claims.ini, %Adjuster%
	If ( Adjuster key = "" )
		IniDelete, Reopened_Claims.ini, %Adjuster%
Third question (hopefully last lol):
This is not as important, but is it possible to IniRead using a partial amount of text from an InputBox? I know I can use IfInString, but it would be tedious because I have to add dozens of companies to a list of IfInStrings.

Code: Select all

;Check claims that were reopened.
InputBox, Company, Type name of adjuster. (Leave blank to see entire list).
;	If you type 'Comp' it can interpret Company1.

IniRead, Company, Reopened_Claims.ini, %Company%
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: Ini Help

16 Aug 2017, 21:40

For your first question, I'd do an IniRead, see if the key is blank (or equivalent to the default), and if it is, just use IniDelete to delete that section - just omit the Key parameter in IniDelete.

Second question: I'm confused what you mean. I'm confused on your IniWrite syntax in that example, given that you are using the Pairs parameter but then also specifying a Key in the fourth parameter - that's mixing the two syntaxes. But it should be possible to put on a date to any value as you please, whether you add it into the Ini Value itself or after you've Read it and use it within just the AHK script.

Third question: Oh, as a sort of filter. I would do an IniRead to get the SectionNames (the list of Sections). Then, I would use a loop with RegExMatch() and find all Section Names that match, putting that inside a list in AHK. Then parse that list (Loop, Parse) with AHK and do a series of IniReads to get what you want. Or if you want to just match one company name partially, do the same approach but no need to loop the RegExMatch, just go with the first result. If you need the results sorted, like getting the company alphabetically, using the Sort command on the list returned from IniRead should be possible.
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

Re: Ini Help

17 Aug 2017, 07:09

Exaskryz wrote:For your first question, I'd do an IniRead, see if the key is blank (or equivalent to the default), and if it is, just use IniDelete to delete that section - just omit the Key parameter in IniDelete.

Second question: I'm confused what you mean. I'm confused on your IniWrite syntax in that example, given that you are using the Pairs parameter but then also specifying a Key in the fourth parameter - that's mixing the two syntaxes. But it should be possible to put on a date to any value as you please, whether you add it into the Ini Value itself or after you've Read it and use it within just the AHK script.

Third question: Oh, as a sort of filter. I would do an IniRead to get the SectionNames (the list of Sections). Then, I would use a loop with RegExMatch() and find all Section Names that match, putting that inside a list in AHK. Then parse that list (Loop, Parse) with AHK and do a series of IniReads to get what you want. Or if you want to just match one company name partially, do the same approach but no need to loop the RegExMatch, just go with the first result. If you need the results sorted, like getting the company alphabetically, using the Sort command on the list returned from IniRead should be possible.

Thank you for your response.
For the first question, I am using an InputBox to delete a claim number once it is closed again. I can't delete a section If I have multiple claim numbers in it. Without searching for company (section) and figuring out how many claims it has left, I am trying to IniDelete the section once all the claims (keys) are closed again.

For the second question, if I am using an InputBox to look at all the company's claims I want to have a MsgBox showing the dates in order. I'm going to try and use Sort like how you answered for the third question.

For the third question, that is perfect. Thank you :). How do I convert the needle to the full name?

Code: Select all

;Haystack = Company
;Needle = Partial company name

Needle := "Brian"	; full name is Brian Johnson

IniRead, Haystack, Reopened_Claims.ini

FoundPos := RegExMatch(Haystack, Needle)

Loop, Parse, Haystack, CSV
{
	;StringReplace, FoundPos, A_LoopField, Haystack
    	StringReplace, Needle, A_LoopField, Haystack
	break
}

MsgBox % Haystack "`n`n" Needle
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: Ini Help

17 Aug 2017, 12:25

Oooh, now that I'm thinking question three through better, I'd recommend doing a Parse Loop *that contains RegExMatch()* (or IfInString()) so that each line is isolated by A_LoopField per the Parsing Loop. If you need the first result only, then you can break upon finding it.

Code: Select all

;Haystack = Company
;Needle = Partial company name

Needle := "Brian"	; full name is Brian Johnson

IniRead, Haystack, Reopened_Claims.ini

Loop, Parse, Haystack, `n, `r ; does it work well as a CSV in IniFiles? Never noticed.
{
If RegExMatch(A_LoopField,Needle)
   {
   match:=A_LoopField ; you could use match.=A_LoopField "|" to get a pipe-separated list of all matches, be sure to include [c]match:=""[/c] before the loop so that you don't append to an old list if you did that
   Break ; remove if you wanted to get the list of all matches
   }
}

MsgBox % Needle "`n`n" match
Your needle, if you only want to match the start of the company name, your Needle could include the ^ anchor for RegEx to tell it to match only at the start of the line.

I don't have a sample Ini to make sure that works, but then if you need to get just the section name, using something like:

Code: Select all

StringSplit, matchS, match, =
key:=matchS1 ; value:=matchS2 if you needed value
And then you could keep a running list of the key as list.=key "|" if you wanted multiple matches for applicable Section Names.

---

As for the first question, I don't know your best method on that. You'd need to search in some capacity to see if all the remaining sections are Closed. Or, you can just make sure to delete all claims that are closed instead of marking them as closed in the Ini - so take care of it one at a time as you close up the claim. You'd still need to then check periodically if Section returns no Key-Value pairs on an IniRead attempt though...

---

As for the second question, if you can end up getting the date to the start of your list, possibly in the YYYYMMDD24HHMISS format then a sort would be possible there. Otherwise, you get into a data structure that I don't recall I've ever solved - maintaining an array or two "paired" arrays where one could be sorted and keep the order of the second. Someone might have such a sorting function for an array made. I'm kind of thinking, although it might be far from optimal, of making an array, then doing a For loop to run through the values and Pop() the array element into a new array using PushAt() to get the order somehow. Sounds like a right mess to be honest and even I don't want to sit down and work on it. Hopefully a better idea dawns on you or someone comes by with one.
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

Re: Ini Help

18 Aug 2017, 09:51

This seemed to do the trick!

I'll keep looking into the second question. Thank you for all your help!
Exaskryz wrote:Oooh, now that I'm thinking question three through better, I'd recommend doing a Parse Loop *that contains RegExMatch()* (or IfInString()) so that each line is isolated by A_LoopField per the Parsing Loop. If you need the first result only, then you can break upon finding it.

Code: Select all

;Haystack = Company
;Needle = Partial company name

Needle := "Brian"	; full name is Brian Johnson

IniRead, Haystack, Reopened_Claims.ini

Loop, Parse, Haystack, `n, `r ; does it work well as a CSV in IniFiles? Never noticed.
{
If RegExMatch(A_LoopField,Needle)
   {
   match:=A_LoopField ; you could use match.=A_LoopField "|" to get a pipe-separated list of all matches, be sure to include [c]match:=""[/c] before the loop so that you don't append to an old list if you did that
   Break ; remove if you wanted to get the list of all matches
   }
}

MsgBox % Needle "`n`n" match
Your needle, if you only want to match the start of the company name, your Needle could include the ^ anchor for RegEx to tell it to match only at the start of the line.

I don't have a sample Ini to make sure that works, but then if you need to get just the section name, using something like:

Code: Select all

StringSplit, matchS, match, =
key:=matchS1 ; value:=matchS2 if you needed value
And then you could keep a running list of the key as list.=key "|" if you wanted multiple matches for applicable Section Names.

---

As for the first question, I don't know your best method on that. You'd need to search in some capacity to see if all the remaining sections are Closed. Or, you can just make sure to delete all claims that are closed instead of marking them as closed in the Ini - so take care of it one at a time as you close up the claim. You'd still need to then check periodically if Section returns no Key-Value pairs on an IniRead attempt though...

---

As for the second question, if you can end up getting the date to the start of your list, possibly in the YYYYMMDD24HHMISS format then a sort would be possible there. Otherwise, you get into a data structure that I don't recall I've ever solved - maintaining an array or two "paired" arrays where one could be sorted and keep the order of the second. Someone might have such a sorting function for an array made. I'm kind of thinking, although it might be far from optimal, of making an array, then doing a For loop to run through the values and Pop() the array element into a new array using PushAt() to get the order somehow. Sounds like a right mess to be honest and even I don't want to sit down and work on it. Hopefully a better idea dawns on you or someone comes by with one.

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Bing [Bot], Blackholyman, Chunjee, DMDComposer, Google [Bot], Jovannb, kjmcneil, TAC109, Xtra and 70 guests