AutoHotkey Community

It is currently May 26th, 2012, 12:24 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: September 20th, 2008, 11:40 pm 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
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! :oops:

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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2008, 2:20 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 21st, 2008, 9:33 am 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2008, 12:13 am 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
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
}
}
}
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], JamixZol, Morpheus, RUBn, SKAN, sks, Yahoo [Bot] and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group