AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need to read a slip.txt file and make an input.txt file

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
artbasement



Joined: 01 Sep 2008
Posts: 47

PostPosted: Thu Sep 04, 2008 2:03 am    Post subject: Need to read a slip.txt file and make an input.txt file Reply with quote

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.
Back to top
View user's profile Send private message MSN Messenger
poo_noo



Joined: 08 Dec 2006
Posts: 137
Location: Sydney Australia

PostPosted: Thu Sep 04, 2008 3:27 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Thu Sep 04, 2008 11:12 am    Post subject: Reply with quote

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
}


Smile
_________________
Back to top
View user's profile Send private message
artbasement



Joined: 01 Sep 2008
Posts: 47

PostPosted: Thu Sep 04, 2008 12:51 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message MSN Messenger
artbasement



Joined: 01 Sep 2008
Posts: 47

PostPosted: Thu Sep 04, 2008 5:49 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
artbasement



Joined: 01 Sep 2008
Posts: 47

PostPosted: Fri Sep 05, 2008 11:06 pm    Post subject: Reply with quote

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
}
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group