USA
Asked — Edited
Resolved Resolved by DJ Sures!

Filereadall Stops Working

Tested with the last version and the previous version

The following code:


1: ClearVariables()
2: $test1 = FileReadAll("c:\dev\test.txt")
3: FileReadClose("c:\dev\test.txt")
4: Print(Length($test1))

Generates an error:

Quote:

Error on line 4: Missing String Quotes or Invalid Expression at index 0: "hello

the "hello" is inside the file, not in the code.


ARC Pro

Upgrade to ARC Pro

ARC Pro will give you immediate updates and new features needed to unleash your robot's potential!

#1  

Strings in EZ-Robot script can only be one line (I think it is because the compiler reads the code one line at a time with no way of encapsulating it, DJ correct me if I am wrong) , since you are reading all the contents of the file I assume you have multiple lines or returns in it (returns are considered invalid chars in the string). You can get around this by using an array and reading one line at a time in a loop like the code below.


$contents = FileReadAll( "c:\dev\test.txt" )
FileReadClose( "c:\dev\test.txt" )
DefineArray( $contentArray, 1 )

repeatuntil( FileReadEnd( "c:\dev\test.txt" ) ) 
  $line = FileReadLine( "c:\dev\test.txt" )
  AppendArray( $contentArray, $line ) 
endrepeatuntil

To find the length just add up the length of all the values in the array.


$arraySize = GetArraySize("$contentArray") -1
$len = 0

repeat($i, 1, $arraySize, 1)
  $len = $i + Length($contentArray[$i])
endrepeat

print($len)

Hope that helps.

PRO
USA
#2  

@mikebmac:

Thanks for that info, after a few hours struggling i didnt expected to be the expected behavior.

I imagine someone writing you need to do tutorial abc or is a bug.

if is true the string is broken, it will be impossible to parse multi line contents/buffers.

Also does not make sense a function filereadall when you can only do filereadline.

no where is explaining the string only handles a single line.

this time i really think there is a learning tutorial missing: "scripting cookbook / tricks"

#3  

ptp, I think I have used this in the past without issue. I will have to check an old project to make sure and will get back to you, but I believe that I had to write an app that removed things like quotes and such to make it work. In the file, does it have a quote after hello?

Checking old project now.

#4  

FileReadLine is what I used. I think my app also removed /r/n and replaced it with a space to make one long line.

PRO
USA
#5  

The original file had multilines, equals, quotes. The one i used for testing has two lines.

PRO
USA
#7  

@DJ

If a RegEx is used some other characters like () are a problem too.

EDIT: No problem with )

I'll close the ticket.

==== Resolution: not supported/By Design.

PRO
Synthiam
#8  

Where do you see () being a problem? An example would help me identify and repair it.

Regex: write once, read never...

PRO
USA
#9  

if the content of the file has a "(" the error is:

Quote:

Error on line 4: Missing ) in Expression

I didn't check other combinations but if there is a RegEx involved,

i'm not a fan of regular expressions, although they are very useful.

PRO
Synthiam
#10  

oh - reading from a file - yeah. i will have to add a new function. A while ago there was a request to read code from a file with functions. This was implemented a long time ago but a function that reads which doesn't execute the function can be created.

I'll have to create a second version of file commands for that.