Asked — Edited

Great Tutorial- Reading And Writing With Files

I don't find the right place to post comments on tutorials, but just wanted to compliment @JustinRatliff on his great tutorial on File Operations with example scripts

Regards, Frank


ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

#1  

Thank you Frank, very much! I appreciate the positive feedback :):):)

#2  

@JustinRatliff I was able to run all of your examples without any issues, but when I used my own data I had some problems with a feature of Split()

A string consisting of alpha chars or mixed alpha and numeric work as I expected, but a string of just numbers is treated as math. This is by design according to an old post I found

User-inserted image

Here is some code and the results showing the issue I can into:


ClearVariables() 

$Chars= ("A,B,C")
$CharsSplit= Split( $Chars, "," ,  0 ) 
Print( "$CharsSplit= " + $CharsSplit)

$Numbers= ("1,2,3")
$NumbersSplit= Split( $Numbers, "," ,  0 ) 
Print( "$NumbersSplit= " + $NumbersSplit)

User-inserted image

I was able to solve my problem by adding one field of alpha to my numeric data.

It might be helpful to add a caution to your great tutorial

Also, it appears that the Script manual states that Split() returns an index instead of the value found

https://synthiam.com/Tutorials/UserTutorials/169/1

User-inserted image

Thanks again for your fine work on the tutorial Frank

PRO
Synthiam
#3  

A number is a number and a string is a string. A number is not a string because a number is used for math. Math uses numbers, not strings. So if you put a number in a variable, the type becomes a number. However, you can still parse/split a list of numbers by adding commas and using the split() command.


$x = "1, 2, 3, 4"

$val = split($x, ",", 2)

print($val)

*note: i updated the EZ-Script manual to reflect the misprint for Split(), thanks!

#4  

@DJSures Thanks for clearing that up! I did have the commas, neglected to add a spaces as you did in your example

I ran a test and adding the spaces to my code worked and I found out there was no need for the parentheses


ClearVariables() 

$x = "1, 2, 3, 4"  # note the spaces
$val = split($x, ",", 3)
print($val)

$x= "1,2,3" # note NO spaces
$val= Split( $x, "," ,  0 ) 
Print( $val)

$x= "1 ,2, 3"  # added spaces
$val = split($x, "," ,  0 ) 
Print( $val)

$x= ("1, 2, 3") # added space and parentheses 
$val = split($x, "," ,  0 ) 
Print( $val)

User-inserted image

Thanks for the quick response Frank