Issue with ReadLn and lines with quotes

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
tbrahmer
Newbie
Posts: 15
Joined: Thu May 06, 2010 10:14 pm

Issue with ReadLn and lines with quotes

Post by tbrahmer » Wed Nov 26, 2014 9:51 pm

Using 14.2.01 on a windows 7 box...

I copy and run the code from Help file for ReadLn:

Code: Select all

Let>k=1
While>line<>##EOF##
  ReadLn>c:\temp\test.txt,k,line
  If>line<>##EOF##
    MessageModal>line
  Endif
  Let>k=k+1
EndWhile
Here is my test.txt file:

Code: Select all

010003000^1^00^NONE
"020072000"^1^04^UNIT AIR
020126001^1^04^UNIT AIR
On the 2nd line with quotes in it, I get an error msg that says "Line: 6 0 not appropriate" (Line 6 is the "While>line<>##EOF##" in the .scp file)

My original file has all fields within quotes, and tab delimited, and I was getting the error for each line. So I started playing with the file (changing delimeter, checking carriage returns, etc.) Then I removed all quotes and it worked fine. Put a couple quotes back in the second line only, and it throws me the error again for that line. Bug or user error?

Thanks!

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

Re: Issue with ReadLn and lines with quotes

Post by Marcus Tettmar » Thu Nov 27, 2014 10:35 am

Hmmm ... not sure what's happened there but will investigate.

In the mean time I would do it this way anyway:

Code: Select all

ReadFile>c:\temp\test.txt,fileData
Separate>fileData,CRLF,fileLines
If>fileLines_count>0
  Let>k=0
  Repeat>k
    Let>k=k+1
    Let>this_line=fileLines_%k%
    MessageModal>this_line
  Until>k=fileLines_count
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

tbrahmer
Newbie
Posts: 15
Joined: Thu May 06, 2010 10:14 pm

Re: Issue with ReadLn and lines with quotes

Post by tbrahmer » Mon Dec 01, 2014 3:20 pm

Thanks for looking into this Marcus. I thought it might be a bug. I will try the alternate method you suggested as well.

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Issue with ReadLn and lines with quotes

Post by mightycpa » Mon Mar 09, 2015 5:24 pm

Hi Marcus, getting the same kind of error. In my case, i get two warnings, one with an uppercase C and another with a lowercase f.

My error also occurs on the ReadLn> command.

I've tracked down what the conditions are that cause this:

It is a double quote in the line being read. The character returned is immediately after the first double quote. There is no error on the closing double quote.

In the op's case, it is zero:

"Line: 6 0 not appropriate"

"020072000"^1^04^UNIT AIR

In my case, the following two lines cause the warning to occur

-- update status record with "COMPLETED"
-- update status record with "failed"

I have 16 files in my folder that I read. Two of them cause this warning, and only these same two have double quotes in them.

Image

Image

Here's my code, in case you have any suggestions about that:

Code: Select all

//force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

Let>v_tablelist=
Let>v_table_order=
Let>INPUT_BROWSE=2
Input>v_filelist,Select Folder to Inspect,
Concat>v_filelist,\*.*
//get list of files in folder
//MessageModal>v_filelist
GetFileList>v_filelist,file_list
Separate>file_list,;,files
//MessageModal>files_count
//GoTo>theend
//loop through list of files
Let>k=0
Repeat>k
  Let>v_line=
  Let>k=k+1
//**BREAKPOINT**
  Let>j=0
  Let>this_file=files_%k%
  MessageModal>%k%, %j%, %this_file%
  ConCat>v_table_order,%k%
  ConCat>v_table_order,COMMA
  ConCat>v_table_order,this_file
  ConCat>v_table_order,COMMA
  GetTime>v_time
  ConCat>v_table_order,v_time
  ConCat>v_table_order,COMMA
  ConCat>v_table_order,CRLF
  ReadFile>this_file,numlines
  If>numlines_count>0
  //read each line
    While>v_line<>##EOF##
      Let>j=j+1
      ReadLn>this_file,j,v_line
      //MessageModal>Line is : v_line
      // does it have "string"
      Position>string.,v_line,1,start_Pos,TRUE
      If>start_Pos>0
        //MessageModal>line
        //**BREAKPOINT**
        Position>SPACE,v_line,start_Pos,end_Pos,TRUE
        if>end_Pos=0
          Position>CRLF,v_line,start_Pos,end_Pos,TRUE
        endif
        //MessageModal>%start_Pos% and %end_Pos%
        If>end_Pos=0
          Let>end_Pos=999
        Endif
        MidStr>v_line,start_Pos,end_Pos,v_table
        ConCat>v_tablelist,v_table
        ConCat>v_tablelist,CRLF
      Endif
    EndWhile
  Endif
  //MessageModal>v_tablelist
Until>k=files_count

Label>theend
UpperCase>v_tablelist,v_final_list
MessageModal>v_final_list
MessageModal>v_table_order

//MessageModal>done!
I'm not sure how to get this in the bug tracker. I'll look around, see if I can.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

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

Re: Issue with ReadLn and lines with quotes

Post by Marcus Tettmar » Tue Mar 10, 2015 2:07 pm

The issue here is not with ReadLn but with the While statement. A bug means that it is not escaping quotes internally. This will be fixed asap.

In the mean time you can either set a different loop check variable, or, my preference, move to using ReadFile and then loop based on line count - this is actually MUCH faster than ReadLn as you only read the file content once.

E.g. to use ReadFile:

Code: Select all

let>this_file=c:\temp\a\test.txt
ReadFile>this_file,data
Separate>data,CRLF,lines
if>lines_count>0
  Let>j=0
  Repeat>j
    Add>j,1
    Let>this_line=lines_%j%
    MessageModal>this_line
  Until>j=lines_count
Endif
Or to use ReadLn and workaround the quote issue do something like this:

Code: Select all

let>this_file=c:\temp\a\test.txt
Let>j=0
Let>v_line=
Let>eof=false
While>eof=false
  Let>j=j+1
  ReadLn>this_file,j,v_line
  If>v_line=##EOF##
    Let>eof=true
  Endif
EndWhile
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Issue with ReadLn and lines with quotes

Post by mightycpa » Thu Nov 12, 2015 9:59 pm

Hi Marcus,

This bug still exists. This time it was a "*/" that created another inappropriate letter of the alphabet.

I found it again, and luckily, I found this thread again. Don't know if you just forgot, or if the fix is complicated, but I thought I'd nudge you on it.

Rewriting my code now. Maybe if you update the docs to encourage/demonstrate the use of ReadLn>, because the help is where I always get the template that I use to start my code.

Thanks
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Issue with ReadLn and lines with quotes

Post by mightycpa » Fri Nov 13, 2015 1:54 pm

Hi Marcus,

You know, it just occurred to me that maybe you have fixed it, but I don't know because I haven't upgraded since the problem was reported!

Didn't want to be unfair. Thanks for all of your support.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

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

Re: Issue with ReadLn and lines with quotes

Post by Marcus Tettmar » Fri Nov 13, 2015 2:16 pm

Yes, was fixed in 14.2.03.

See:
https://www.mjtnet.com/mswhatsnew.htm
Fixed: Loop variables containing " character causing error in Repeat and EndWhile
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