 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
artbasement
Joined: 01 Sep 2008 Posts: 52
|
Posted: Sat Sep 20, 2008 10:40 pm Post subject: Look for a number in two files and if different start script |
|
|
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
} |
|
|
| Back to top |
|
 |
Guest
|
Posted: Sun Sep 21, 2008 1:20 am Post subject: |
|
|
| Code: | #IfWinActive Salesperson
~Enter:: ; the ~ makes it send an enter
Sleep, 2000
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
If (transactionNum1!=transactionNum2)
Return ; if not the same -> stop
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
}
Return
#IfWinActive ; disables your code for when not in Salesperson |
|
|
| Back to top |
|
 |
artbasement
Joined: 01 Sep 2008 Posts: 52
|
Posted: Sun Sep 21, 2008 8:33 am Post subject: |
|
|
As my code seemed unreliable, I was thinking it should run in a loop and not be triggered by the final 'Enter' on the till system, but be triggered by the numbers being different instead. This is because the currslip.txt file can take between 1 and 4 seconds to appear, so sometimes the code "misses the boat" and never makes the input file.
Can I make your code run in a loop? |
|
| Back to top |
|
 |
artbasement
Joined: 01 Sep 2008 Posts: 52
|
Posted: Sun Sep 21, 2008 11:13 pm Post subject: |
|
|
Just for the record, came up with this in the end, thanks for the part of the code that compares.
| 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, 4 ; get the first 4 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,"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
Filedelete, c:\sa\num.txt
FileAppend, %T1%, c:\sa\num.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
Filedelete, c:\sa\num.txt
FileAppend, %T1%, c:\sa\num.txt
}
}
}
} |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|