AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: November 1st, 2008, 4:53 pm 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
I have written some code which compares the transaction number in a currslip.txt file to a num.txt file to decide if to activate credit card payment software. The problem is that sometimes the transaction number is on line 15 instead of line 14.

How can I get my script to look on line 14 and line 15 for the number to compare and also write the actual line (14 or 15) with the transaction number to the input.txt and num.txt file file? Here is the script....

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, 6 ; get the first 6 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,"Tendered")) 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,"Exchange")) 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
}
}
}
}


and this is what the content of currslip looks like

Quote:
Your Company Name
Your Company Address
Your Company Address
Your Company Address 1234
Telephone 1234567
Fax 1234568
yourcompany@yourisp.co.za
www.yourcompany.com
Reg. No. YourRegistrationNumber


41265 18/10/2008

Sample Item 4 1 18.00
_______
18.00
_______

Amount Tendered: 18.00
Change : 0.00
Credit Card

1 line items
1 items

Salesperson: Chris
4:48 pm
Have a nice day


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2008, 5:52 pm 
I would personally use:

Loop, Read, File

And:

A_Index


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2008, 5:58 pm 
Loop, Read, File.Txt
{
If (A_Index == 15)
String := A_LoopReadLine
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2008, 6:12 pm 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
I have to admit I am very new to programing, so I am not sure how to use the examples you have given me. Is there any chance you could edit my code to show me how to do it?
Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2008, 6:32 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
artbasement wrote:
I have to admit I am very new to programing, so I am not sure how to use the examples you have given me. Is there any chance you could edit my code to show me how to do it?
Thanks


Over the past 2 months, you've created at least 8 new threads on this exact topic:
artbasement wrote:
1. Find Transaction Number on Line 14 or 15
2. Look for a number in two files and if different start script
3. How can I loop this?
4. Compare Number but Ignore the Date
5. Need to say "if file.txt contains "Credit Card&quo
6. How to find the Last Occurance of a Minus Number
7. Need to read a slip.txt file and make an input.txt file
8. Need to find Amount Tendered in text file


It would have been helpful to keep all that information in 1 thread, so people who assist you get a better idea of what's going on, and you don't have to post the same code over and over and over. Most of the regular forum members have given you code by now, and had you stuck with one thread someone probably would have finished it for you already. Instead you have this collage that you're still begging other people to finish.

In 2 months you could've learned more than enough AHK to do this yourself.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2008, 10:17 pm 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
Thank you for your input. The reason I posted a fresh thread is because we have been using this code for nearly 2 months in a chain of shops and it has been working fine up until the point we found this little problem with it.

It seemed better to start a new thread and just say "this is the code and this is the problem we have" rather than showing a load of code ideas that we didn't end up using in all the other threads.

I admit the code is a "collage" of code helpfully given by members of this forum, but I am not a programer and certanly don't like to feel that I am "begging" for it, rather that I am posing a simple simple question to a forum of people who have vastly more knowledge and experiance than me. With respect, do you know the answer jaco...?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 1st, 2008, 11:53 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3329
Location: Simi Valley, CA
Code:
; ... previous lines
  FileReadLine, transactionNum1, c:\sa\currslip.txt, 14 ; reads 14th line currslip.txt
  If transactionNum1 is NOT INTEGER ; assuming the transaction number is an integer ...
    FileReadLine, transactionNum1, c:\sa\currslip.txt, 15 ; reads 15th line currslip.txt
; ... the rest of the code

:?:

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2008, 2:48 am 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
Thanks VxE, works perfectly now like this! :D

Code:
 FileReadLine, transactionNum1, c:\sa\currslip.txt, 14
  StringLeft, transactionNum1, transactionNum1, 6
 If transactionNum1 is NOT INTEGER
  FileReadLine, transactionNum1, c:\sa\currslip.txt, 15
  StringLeft, transactionNum1, transactionNum1, 6


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 54 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