Asked
Resolved Resolved by ptp!

Filereadline Getting Error Data Is In Wrong Format

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

ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

PRO
Synthiam
#9   — Edited

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


// assign the filename that we'll write and read from
var filename = "c:\\temp\\doit.txt";

// If the file exists, delete it cause we're making a new one
if (File.exists(filename))
  File.delete(filename);

// Download the contents of google's home page and put it in a file
File.appendString(filename, Net.hTTPGet("http://www.google.ca";));

// loop until the end of the line and print each line separated by a blank line
while (!File.isReadEnd(filename)) {

  print(File.readLine(filename));
  print();
}

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

PRO
USA
#10  

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.

PRO
Synthiam
#11  

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

PRO
USA
#12  

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.

User-inserted image

PRO
USA
#13   — Edited

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.

PRO
USA
#14  

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.

PRO
USA
#15  

[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?

PRO
USA
#16   — Edited

a working example:

var baseUrl = "https://synthiam.com";;
var url1 = "https://synthiam.com/Community/Questions";;

print("Downloading questions");
var content = Net.hTTPGet(url1);

print("Content length=" + content.length);

print("Questions found:");

var pos = 0;
do
{
  //This method returns -1 if the value to search for never occurs.
  pos = content.indexOf("/Community/Questions/", pos);
  
  if (pos>=0)
  {
      beginPos = pos

      //search for a double quote after finding the begin string
      pos = content.indexOf("\"", beginPos);
      if (pos>0)
      {
        endPos = pos;
        var link = content.substring(beginPos, endPos);
        print (baseUrl + link);
      }
  }
}
while(pos>=0);

   

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