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 

Find Transaction Number on Line 14 or 15

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



Joined: 01 Sep 2008
Posts: 56

PostPosted: Sat Nov 01, 2008 3:53 pm    Post subject: Find Transaction Number on Line 14 or 15 Reply with quote

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





PostPosted: Sat Nov 01, 2008 4:52 pm    Post subject: Reply with quote

I would personally use:

Loop, Read, File

And:

A_Index
Back to top
Guest






PostPosted: Sat Nov 01, 2008 4:58 pm    Post subject: Reply with quote

Loop, Read, File.Txt
{
If (A_Index == 15)
String := A_LoopReadLine
}
Back to top
artbasement



Joined: 01 Sep 2008
Posts: 56

PostPosted: Sat Nov 01, 2008 5:12 pm    Post subject: Reply with quote

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



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Sat Nov 01, 2008 5:32 pm    Post subject: Reply with quote

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



Joined: 01 Sep 2008
Posts: 56

PostPosted: Sat Nov 01, 2008 9:17 pm    Post subject: Reply with quote

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



Joined: 07 Oct 2006
Posts: 3254
Location: Simi Valley, CA

PostPosted: Sat Nov 01, 2008 10:53 pm    Post subject: Reply with quote

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

Question
_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!
Back to top
View user's profile Send private message
artbasement



Joined: 01 Sep 2008
Posts: 56

PostPosted: Sun Nov 02, 2008 1:48 am    Post subject: Reply with quote

Thanks VxE, works perfectly now like this! Very Happy

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
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
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