I have written some code which compares the transaction number in a currslip.txt file to a num.txt file to decide if to activate credit card payment software. The problem is that sometimes the transaction number is on line 15 instead of line 14.
How can I get my script to look on line 14 and line 15 for the number to compare and also write the actual line (14 or 15) with the transaction number to the input.txt and num.txt file file? Here is the script....
Code:
Loop
{
IfNotExist, c:\sa\input.txt
{
Sleep, 1000
FileReadLine, transactionNum1, c:\sa\currslip.txt, 14 ; reads 14th line currslip.txt
FileReadLine, transactionNum2, c:\sa\num.txt, 1 ; reads 1st line of num.txt
StringLeft, transactionNum1, transactionNum1, 6 ; get the first 6 characters
If (transactionNum1!=transactionNum2)
{
FileRead, currslip, c:\sa\currslip.txt
StringReplace, currslip,currslip, `r`n, `n, All
StringReplace, currslip,currslip, `r, `n, All
StringSplit, L,currslip, `n
If (instr(currslip,"Tendered")) AND (instr(currslip,"Credit Card"))
{
needle := "Amount Tendered: "
halfslip := SubStr(currslip, InStr(currslip, needle) + StrLen(needle))
amount := SubStr(halfslip, 1, InStr(halfslip, "`n") - 1 )
StringSplit, T, L14, %A_Space%
output = 2=0`n1=%T1%`n3=%amount%`n99=0
FileAppend, % output, c:\sa\input.txt
Filedelete, c:\sa\num.txt
FileAppend, %T1%, c:\sa\num.txt
}
If (instr(currslip,"Exchange")) AND (instr(currslip,"Credit Card"))
{
needle := "-"
halfslip := SubStr(currslip, InStr(currslip, needle,"",0) + StrLen(needle))
amount := SubStr(halfslip, 1, InStr(halfslip, "`n") - 1 )
StringSplit, T, L14, %A_Space%
output = 2=20`n1=%T1%`n3=%amount%`n99=0
FileAppend, % output, c:\sa\input.txt
Filedelete, c:\sa\num.txt
FileAppend, %T1%, c:\sa\num.txt
}
}
}
}
and this is what the content of currslip looks like
Quote:
Your Company Name
Your Company Address
Your Company Address
Your Company Address 1234
Telephone 1234567
Fax 1234568
yourcompany@yourisp.co.za www.yourcompany.com Reg. No. YourRegistrationNumber
41265 18/10/2008
Sample Item 4 1 18.00
_______
18.00
_______
Amount Tendered: 18.00
Change : 0.00
Credit Card
1 line items
1 items
Salesperson: Chris
4:48 pm
Have a nice day