PRO
dbeard
USA
Asked
Resolved by ptp!
I have created a file by downloading data from the web.
this is the line of code
FileWrite($DataFile,HTTPGet($url1))
Where $DataFile is the file location on my harddrive and url1 is the where the data is on the web.
The data gets successfully wrote to the hard drive.
Now my next line of code is $line = FileReadLine($DataFile).
The first line of the Data file is: <!DOCTYPE html>
This fails with the error Input string was not in a correct format.
Now this used to work but with ARC this fails.
What format should the Datafile be in for this to continue?
Related Hardware EZ-B v4
If you're parsing data, i'd recommend using the javascript. The EZ-Script is quite terrible at parsing strings. While nothing has changed in the ezscript compiler, i imagine the webpage you're querying may have some changes that is breaking the parser. EZ-Script is not my favorite haha. Javascript is just so much more powerful (and 1000 times faster)
My goodness, I gotta learn Javascript. Do you have any recommendations on educational literature I can read that would give me a good idea of how to learn it?
Dave, it's so similar to ezscript... but easier i think.
The commands are all categorized in their own sections. For example, all File commands start with File. And all servo commands start with Servo. When you type the category, the drop down will display all commands in that category.
So you can move your robot by typing...
or you can create a variable like
or you can make reusable functions like
Or you can get super crazy...
IF conditions have open and closing braces...
But... how ever you decide to learn javascript, the Blockly in ARC generates javascript. So you can just use Blockly and look at the JavaScript code it generates...
Sweet. Thanks. I'll be looking closer at all this soon.
DJ I get the impression that ez-script wouldn’t be supported for much long and removed??
Does that mean all my ez-scripts projects will have to be converted to JavaScripts?
Question. I don't know JavaScript. But attempting something easy in JavaScript.
This code is the code in Blockly
It returns an error object has no method.
Can you get me past this hurdle. Also any suggestions on a book or website to help me learn java script.
JS equivalent:
test version:
Dbeard: ARC beta v2020.03.17.00 fixes the Blockly issue with getVoltage and adds new File commands: https://synthiam.com/Products/Releases/ARC-Beta-2020-03-17-00-19052
Also, here's some code similar to PTP's but it deletes the file and reads from it...
PTP: EZ-Script won't be removed, as it'll continue to support legacy programs. We'll probably see it phase out over time. But it has always had weird bugs with reading files because of the way it handled quotes and other stuff. Future development on ezscript is super low on priority
One more issue I am trying to play audio via a soundboard which is added to my project and it says there are no sound boards.
Any thoughts. I have followed the Blockly tutorial on playing sound and when I use the pull down list I don't see my sound board either.
Soundboard EZB or Soundboard PC? Only soundboard EZB are supported for "Play Audio" command. You want to use the Utility -> ControlCommand for the soundboard PC
DJ. Thanks. I think I have everything I need, except one item. In JavaScript I see the file. options. But nothing about writing a file. I see the ability to append, but not write a new file. Or am I missing it.
Sometimes I almost lose hope... did you read my post ? I took time to open the ARC, test the code and post a valid example.
Please check post #7
I've used File.appendString it creates a new file or appends to an existing one.
If you don't want to append you can do a File.Delete before doing a File.appendString.
To be honest, It's not your fault is mine.
Ok, yes. I was looking through the comments and missed your comment because it hides the top most and only shows the recent. Started at #8 as the first visible post. So sorry, didn't even realize that had happened until I saw your post and was looking for #7.
Thanks.
[quote][/quote]I am able to read and write the data file. But now I need to search through it and find a string.
I am using var linein = File.readLine(dataFile);
var n = dow.search(linein); (this is line 20 the error is referencing.)
but receive the following error:
Execution Error Line 20 Col 2 - Line 1: Invalid regular expression
another bit of help?
a working example:
the above code downloads Synthiam's front page questions and parses que questions links using a indexOf.
The method search uses regular expressions.
help with JS: https://www.w3schools.com/jsref/jsref_indexof.asp
@DJ: I believe there are some bugs with File class exported to Jint.
*** code edited ***
This is the html content:
Red is the "begin text" and Blue is the end
special attention to substring method: https://www.w3schools.com/jsref/jsref_substring.asp
Definition and Usage The substring() method extracts the characters from a string, between two specified indices, and returns the new sub string.
This method extracts the characters in a string between "start" and "end", not including "end" itself.
What bugs are you noticing with the File class? And what version of ARC are you using? (latest?)
weird stuff going on, maybe is a consequence of a single bug. I'll post simple code to demo the issue.
first time (file does not exist)
Close ARC, Open ARC run the script:
Q: without a close and explicit open how you control reads and writes ?
Locks the file, and you need to close ARC.
Reading from a File locks the file too so you need to close ARC.
PTP
In your answer in #16. I think I follow but what I cant figure out is why doesn't your code download all the questions. Why does it stop after 9.
I don't see anything in your code that says just show the first 9 questions.
That's a different question, the website content is dynamic, does not make sense to list all the questions when a page is loaded. Look to twitter when you scroll down to the last visible post, the page requests more content from the server same thing here.
synthiam page captures the document page scroll:
and calls the function addSearchContent
the function executes an ajax call to the server /api/search/byType and the server returns more html content (i.e. questions) that content will be appended to a specific document placeholder:
short story when you request the questions page a fixed number of questions are returned, after each scroll more questions are retrieved from the server.
you can read more about "infinite scroll": http://harshw.com/infinite-scroll-using-jquery-asp-net-mvc-mustache-entity-framework-paginate/
You lost me at infinite scroll.
But I do understand this (I think) the code only reads a page at a time. It will take me some time to digest the above.
one last question for the day. BTW. I have it working now and getting the data from the page thanks to your help.
Here is the question. this is what the data looks like: >5:26 PM</td> The data I want is the 5:26 PM. But depending on the time of day it could be 10:26 PM. Is there a one-liner function that can pull the 5:26 PM or 10:26 PM out from between those markups really easy without including the other stuff?
If the file is locked, you have to close the file from reading with the close command. Because reading the file keeps the file open while you read it.
I missed that method, but i don't see an equivalent writeClose
Because there is no write. It's append. Appending just keeps appending to an existing file or creates a new one. There's no reason to keep a file open for appending. The only point to keeping the file open for reading is to know the position.
I've added two new methods for getting the current read position and getting the file length. It'll be in today's release.
This commands locks the file and does not release the file. Is that an expected behavior ?
@dbeard:
Example to capture the red part
The forum break's the JavaScript code, posted code picture:
@DJ Please read my previous post!
Here is my program for getting dow jones data. I know it is a mess, but it works.
Use this to see what files you have locked: https://synthiam.com/Products/Controls/General/File-Information-16183
Thanks everyone for the help.