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

ARC Pro is your passport to a world of endless possibilities in robot programming, waiting for you to explore.

PRO
USA
#18  

This is the html content:

User-inserted image

Red is the "begin text" and Blue is the end

PRO
USA
#19  

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.

PRO
Synthiam
#20  

What bugs are you noticing with the File class? And what version of ARC are you using? (latest?)

PRO
USA
#21  

weird stuff going on, maybe is a consequence of a single bug. I'll post simple code to  demo the issue.

PRO
USA
#22  
function PrintLines(filename) 
{
  var lineIx = 0;
  while (!File.isReadEnd(filename)) 
  {
    var line = File.readLine(filename);
    print(lineIx + " line:" + line);
  }
}


var filename="c:\\temp\\lines.txt";

var now = new Date().toLocaleString();
if (!File.exists(filename))
{
  print("file does not exist");
  File.appendStringLine(filename, now + ">>" + "First time");
}
else
{
  print("file exists");
  File.appendStringLine(filename, now + ">>" + "foo");
}

print("reset read file");
File.readReset(filename);

print("PrintLines");
PrintLines(filename);

print("add bar");
File.appendStringLine(filename, now + ">>" + "bar");

print("PrintLines");
PrintLines(filename);

first time (file does not exist)

User-inserted image

Close ARC, Open ARC run the script:

User-inserted image

Q: without a close and explicit open how you control reads and writes ?

File.appendStringLine

Locks the file, and you need to close ARC.

PRO
USA
#23  

Reading from a File locks the file too so you need to close ARC.

User-inserted image

PRO
USA
#24  

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.