I have managed to cobble together a script for my shop till system that takes information from a currslip.txt file and makes an input.txt file to activate credit card software. The card software then deletes the input file and waits for another.
I would like to activate the script by comparing the transaction number in line 14 of currslip.txt to line 1 in a num.txt file that is created when input.txt file is created, so it is not deleted by the card terminal.
The idea being that if the number is the same, i.e. 402 & 402 the script will not make an input.txt file and therefore not activate the card terminal, but if the numbers are not the same, say 402 & 403 the script will activate, make an input.txt and delete the num.txt file and make a new num.txt file with the new transaction number to continue the process.
The script I have at the moment is activated by the final 'Enter' key press on the till, but it doesn't always work. A bit of expert assistance here would save me a lot time and embarassement!
Code:
$Enter::Send {Enter}
#IfWinActive Salesperson
Enter::
Send {Enter}
Sleep, 2000
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,"Change")) 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
}
If (instr(currslip,"-")) 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
}