The raw text from the section I need looks like this (copied from the MsgBox):
Code: Select all
---------------------------
AHK_CQT_2337778109
---------------------------
Billing & CollectionsBills (Unpaid)1Ledger62Unposted1Payment History12Payment Accounts1Credit Checks
Create New: Adjustment · Credit · Charge · BillOther: Balance Transfer · Promise-to-Pay · Repost MRCs · Rerate Usage · History · Full Ledger
Payment # Ref # Method Source Auth Code Date Rep Agent Amount Applied To
76614 1159SPLIT Manual Check
INHOUSE - 10/26/2021 ErwinT - $18.35 160786: $18.35
Options
68606 13872SPLIT Manual Check
INHOUSE - 9/21/2021 ErwinT - $18.44 147518: $18.44
Options
63044 13858SPLIT Manual Check
INHOUSE - 8/25/2021 ErwinT - $18.44 134506: $18.44
Options
56367 13837SPLIT Manual Check
INHOUSE - 7/26/2021 ErwinT - $18.44 121630: $18.44
Options
48261 13819SPLIT Manual Check
INHOUSE - 6/16/2021 ErwinT - $18.50 109128: $18.5
Options
42548 13805SPLIT Manual Check
INHOUSE - 5/19/2021 ErwinT - $17.50 97004: $17.5
Options
35363 13775 Manual Check
INHOUSE - 4/14/2021 ErwinT - $0.06 85058: $0.06
Options
29692 13758SPLIT Manual Check
INHOUSE - 3/16/2021 ErwinT - $17.44 85058: $17.44
Options
28854 62902461259 CC
INHOUSE 106576 3/11/2021 RaymondS - $17.44 61933: $1
73253: $16.44
Options
19034 13717SPLIT Manual Check
INHOUSE - 1/21/2021 ErwinT - $18.44 61933: $17.44
73253: $1
Options
View Moreor View All
Services & Activity
Each new payment line starts with a tab and a whole number. The line below that is part 2 of that same payment. Any lines between that line and the next line that starts with a tab and a whole number all belong to that same payment, just different invoices are paid. So in the end, for example, if I was looking at which invoices were paid with payment # 28854, I would want that section of the final product to look something like:
28854~62902461259~CC~106576~3/11/2021~RaymondS~$17.44~61933: $1
28854~62902461259~CC~106576~3/11/2021~RaymondS~$17.44~73253: $16.44
I have regexed out all the stuff I don't need from the text and replaced all tabs with "~" to get this (copied from the MsgBox)(code below):
Code: Select all
---------------------------
AHK_CQT_2337372890
---------------------------
Billing & CollectionsBills (Unpaid)1Ledger62Unposted1Payment History12Payment Accounts1Credit Checks
Create New: Adjustment · Credit · Charge · BillOther: Balance Transfer · Promise-to-Pay · Repost MRCs · Rerate Usage · History · Full Ledger
~Payment #~Ref #~Method~Source~Auth Code~Date~Rep~Agent~Amount~Applied To~ ~
~76614~1159SPLIT~Manual Check
10/26/2021~$18.35~160786: $18.35
~68606~13872SPLIT~Manual Check
9/21/2021~$18.44~147518: $18.44
~63044~13858SPLIT~Manual Check
8/25/2021~$18.44~134506: $18.44
~56367~13837SPLIT~Manual Check
7/26/2021~$18.44~121630: $18.44
~48261~13819SPLIT~Manual Check
6/16/2021~$18.50~109128: $18.5
~42548~13805SPLIT~Manual Check
5/19/2021~$17.50~97004: $17.5
~35363~13775~Manual Check
4/14/2021~$0.06~85058: $0.06
~29692~13758SPLIT~Manual Check
3/16/2021~$17.44~85058: $17.44
~28854~62902461259~CC
106576~3/11/2021~RaymondS~$17.44~61933: $1
73253: $16.44
~19034~13717SPLIT~Manual Check
1/21/2021~$18.44~61933: $17.44
73253: $1
View Moreor View All
Services & Activity
---------------------------
OK
---------------------------
Then when the script was done evaluating the text, I would create another loop that would iterate through the count var and reassemble the parts of the text that pertained to each payment number.
My code at that point where I was ready to throw a match over my shoulder and walk away:
Code: Select all
GoSub, getAcctNumNamerevio
meat := RegExMatch(text, "Billing & Collections.*Services & Activity", meatier )
meatier := RegExReplace(meatier, "`r`n|`r`r|`n`n", "`n")
meatier := RegExReplace(meatier, "`t", "~")
meatier := RegExReplace(meatier, "INHOUSE~|-~|ErwinT~| ~Options`n|^~")
count := 1
Loop, Parse, meatier, `n
{
If (A_Index < 4)
continue
payField%A_Index% := % A_LoopField
If (RegExMatch(A_LoopField, "^~"))
{
payIndex%count% := % A_Index
newInvs := % payIndex%count% . "," . newInvs
;MsgBox % payField%A_Index%
count += 1
}
}
Sort, newInvs, N D,
count2 := 1
Loop, Parse, newInvs, `,
{
loop := A_LoopField + 1
payField := payIndex%count2%
payNum%count2% := payField%A_LoopField% . "~" . payField%loop%
loop := loop + 1
If (loop = (newInvs[count2] + 1))
{
payNum%count2% := % payNum%count2% . "|"
Continue
}
Else
{
payNum%count2% := payNum%count2% . "~" . payField%loop%
}
count2 := % count2 + 1
MsgBox % payNum%count2%
}
MsgBox % count
Return
getAcctNumNamerevio:
{
tmpCB := ClipBoard
ClipBoard := ""
Send ^a
Send ^c
ClipWait, 2
text := ClipBoard
text := RegExReplace(text, "m)`r`r|`r`n|`n`n", "`n")
array := StrSplit(text, "`n")
acctStuff := StrSplit(array[4],")")
acctNum := SubStr(acctStuff[1],2,-1)
acctName := trim(acctStuff[2])
ClipBoard := tmpCB
WinActivate, rev.io
Click, 11 235
}
Return
I don't necessarily want someone to FIX my code (although if you want, hey , I won't stop you ) ... a smack upside the head and a point in the right direction would be helpful. Also, if you have any hints on how I can pretty it up, speed it up, or just make things work better with fewer errors would be great. I am admittedly a "Search and Destroy" writer when trying to write my scripts, so I frequently opt for "well, it works" over trying to find the best, most efficient way to write a piece of code.
I'm walking away from this mess for a bit and will check later tonight or in the morning for any responses ... I need a drink ...