##EOF## in 7.409 - Resolved

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
MacschedStudent
Junior Coder
Posts: 36
Joined: Fri Oct 12, 2007 5:55 pm
Location: federal way wa
Contact:

##EOF## in 7.409 - Resolved

Post by MacschedStudent » Thu Mar 13, 2008 5:10 pm

Hey Guys I have never used the logic in this way before - I'm trying to count the lines in a simple text file so to simplify the test I created a text file with only one line. I double-checked to make sure there was no blank space after the line then I ran the standard RLN code to count the lines

Code: Select all


Let>x=1
Label>cstart
ReadLn>Cntr.log,x,linex
MessageModal>linex
If>linex=##EOF##,cfinish
MessageModal>x
Let>x=x+1
Goto>cstart
Label>cfinish

MessageModal>x
to my surprise the result returned was 2 - how can this be ? Is the logic in 7.409 counting the ##EOF## as an additional line. I then added:

x=x-1 at the end of the code and got the correct line count...any ideas..??
Last edited by MacschedStudent on Thu Mar 13, 2008 9:20 pm, edited 1 time in total.

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Mar 13, 2008 5:23 pm

It's not Macro Scheduler counting the EOF, it's your script. Look carefully at your script. YOU are counting the EOF. Hint: You're initialising x to 1 and incrementing it after each line has been read. So after the first line has been read x is now 2. You then go back up to the top of the loop and get EOF and then jump out. x is now 2.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MacschedStudent
Junior Coder
Posts: 36
Joined: Fri Oct 12, 2007 5:55 pm
Location: federal way wa
Contact:

Post by MacschedStudent » Thu Mar 13, 2008 9:19 pm

Marcus :

It took me a minute but your right:

when line 1 is read its not at the end: it still has to loop back to cstart to find the ##EOF## line and because it passes through the increment x logic when it gets to the top again the count will always be 2
DuuuuuuuuuuuuHHH!!

I guess I will keep the x-1 statement. Because if I attempt to start with x=0 it wont work because there is no line 0. - Thanks Marcus

:oops:

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Mar 13, 2008 9:31 pm

Either:

1) Keep x-1 at the end

Or

2) Initialise to zero but read line x+1 each time

Or

3) If you just want to know how many lines are in a text file, just do this:

ReadFile>filename,filedata
Separate>filedata,CRLF,lines
MessageModal>lines_count
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts