AutoHotkey Community

It is currently May 26th, 2012, 11:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: September 4th, 2008, 3:03 am 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
Hi, I am new to autohotkey and could really do with an example of how to do this....if it is possible at all that is....

My till system makes a currslip.txt file after every transaction that looks like this

Quote:
Cash Sale

265 04/09/2008

Sample Item 7 1 21.00
Sample Item 8 1 22.00
_______
43.00
(Total V.A.T. 0.00) _______


Amount Tendered: 43.00
Change : 0.00
Credit Card

1:41 am
Have a nice day


And I have Credit Card software that will start automaticly if an input.txt file is created in it's directory, like this....

Quote:
2=0
1=265
3=43.0
99=0


Would it be possible to read the currslip.txt file and IF it says "Credit Card" make an input file with the the trans No, Amount and type?

The important thing is that the code would have to only make one input.txt file per transaction.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 4th, 2008, 4:27 am 
Offline

Joined: December 8th, 2006, 5:17 am
Posts: 248
Location: Sydney Australia
Look up Fileread and Fileappend
This should get you started.

Code:
IfExist input.txt   ;check for an existing file
   {
   msgbox, I exist
   Filedelete input.txt   ;delete if found
   }
FileRead, saletransaction, currslip.txt
If  saletransaction contains Credit Card   ; Look for the words Credit Card in currslip.txt
   {
   ; loop to strip out the blank lines
      Loop
   {
       StringReplace, saletransaction, saletransaction, `r`n`r`n, `r`n, UseErrorLevel
       if ErrorLevel = 0  ; No more replacements needed.
           break
   }
      FileAppend, %saletransaction%, input.txt ; create the input file
      Msgbox, A credit card sale
      Return
   }
Else
   {
      Msgbox, NOT a credit card sale
      Return
   }
Return


The above does the first part of what you need. But you will need to define some definite rules on where to find the values you want to assign against 1= , 2= , 3= and 4=. I.E. position in the file, the length of the data etc etc

_________________
Paul O


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 4th, 2008, 12:12 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Code:
currslip=
(
Cash Sale

265 04/09/2008

Sample Item 7 1 21.00
Sample Item 8 1 22.00
_______
43.00
(Total V.A.T. 0.00) _______


Amount Tendered: 43.00
Change : 0.00
Credit Card

1:41 am
Have a nice day
)

StringReplace, currslip,currslip, `r`n, `n, All
StringReplace, currslip,currslip, `r, `n, All
StringSplit, L,currslip, `n

If ( L14 = "Credit Card" )
{
  StringSplit, T, L3, %A_Space%
  output = 2=0`n1=%T1%`n3=%L8%`n99=0 
  MsgBox, % output
}


:)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 4th, 2008, 1:51 pm 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
Wow, thanks for the code...not sure if I need to delete the input.txt file as the card software does that instantly after it is created and read. Can I get rid of that bit?

Also with the second part of the code that reads the currslip.txt file...where should that go in relation to the first part of the code...I am a bit new to all this..really.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 4th, 2008, 6:49 pm 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
Ok, this is how far I have got....

I am using a hot key to start the thing off and to select "credit card" on the till...but I would like to make it start the query after I have pressed Enter when I am in the final window of the sale. It would need to wait a couple of seconds for the currslip.txt to be created. I have found out which active window that is...but enter gets dissabled all the time when I am testing with this script...

Code:
WinWait, ahk_class Tget_salesperson_code
Enter::
{
   msgbox start
}


The rest of the code below works really fast but only one thing to sort out...depending on the amount of items on the receipt the sub total figure will move down the page from line 18 to 19 and so on.

Code:
NumPadAdd::
Send !2,
FileRead, currslip, currslip.txt


StringReplace, currslip,currslip, `r`n, `n, All
StringReplace, currslip,currslip, `r, `n, All
StringSplit, L,currslip, `n


If  currslip contains Credit Card
{
  StringSplit, T, L14, %A_Space%
  output = 2=0`n1=%T1%`n3=%L18%`n99=0
  FileAppend, % output, input.txt
}



The receipt text looks like this

Quote:
Cash Sale

Your Company Name
Your Company Address
Your Company Address
Your Company Address 1234
Telephone 123-4567
Fax 123-4568
yourcompany@yourisp.co.za
www.yourcompany.com
Reg. No. YourRegistrationNumber


272 04/09/2008

Sample Item 6 1 20.00
Phone 1 23.50
_______
43.50
(Total V.A.T. 3.50) _______


Amount Tendered: 43.50
Change : 0.00
Credit Card

2 line items
2 items

Salesperson: Chris Ostwald
4:12 pm
Have a nice day


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2008, 12:06 am 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
Just to let you know that it is all sorted now and works like magic.
The finished code is started by the enter key when used in the final window of a sale. Code looks like this...is anything missing or bad practice?

Code:
$Enter::Send {Enter}
#IfWinActive Salesperson
  Enter::
  Send {Enter}
  Sleep, 3000

FileRead, currslip, currslip.txt

StringReplace, currslip,currslip, `r`n, `n, All
StringReplace, currslip,currslip, `r, `n, All
StringSplit, L,currslip, `n

needle := "Amount Tendered: "
halfslip := SubStr(currslip, InStr(currslip, needle) + StrLen(needle))
amount := SubStr(halfslip, 1, InStr(halfslip, "`n") - 1 )

If  currslip contains Credit Card
{
  StringSplit, T, L15, %A_Space%
  output = 2=0`n1=%T1%`n3=%amount%`n99=0
  FileAppend, % output, input.txt
}


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey and 19 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