Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
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:


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

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

AI Support Bot
Related Content
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
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 )

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])


Hope that helps.

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"
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.
FileReadLine is what I used. I think my app also removed /r/n and replaced it with a space to make one long line.
The original file had multilines, equals, quotes.
The one i used for testing has two lines.

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

*EDIT*: No problem with )

I'll close the ticket.

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

Regex: write once, read never...
if the content of the file has a "(" the error is:


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.
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.