locked
File.LastError RRS feed

  • Question

  • Is there a way to use File.LastError to check an EOF propriety while reading a file? I guess I would need the error number but I don't have it.
    Thursday, November 18, 2010 3:33 PM

Answers

  • Dick033,

    In the following snippet I printout the file.lasterror contents as I go through each line of a created file.  When you run the snippet you'll see that it only prints out as blank even when I read past the end of the file.  When the value that is in the variable "Contents" becomes blank is when the routine stops reading.  This tells me that you can't use File.LastError to detect EOF.  You can use blank.

    Jricestk

    For x=1 To 3
      File.WriteLine("c:\testfile.txt",x,x)
    EndFor
    x=0
    status="True"
    while status="True"
      x=x+1
      contents=File.ReadLine("c:\testfile.txt",x)
      TextWindow.WriteLine(contents)
      TextWindow.WriteLine(File.lasterror)
      If contents=""then
        status="False"
        endif
      TextWindow.WriteLine("Here")
    endwhile


    Jricestk
    • Marked as answer by litdev Tuesday, November 23, 2010 8:50 PM
    Thursday, November 18, 2010 11:44 PM
    Answerer
  • Small Basic does not throw an exception if File function fails. When File function fails small basic application handles exception and does not crash and writes the error message in File.LastError.
    Sorry My Bad English
    • Marked as answer by litdev Tuesday, November 23, 2010 8:50 PM
    Saturday, November 20, 2010 9:03 PM

All replies

  • Dick033,

    In the following snippet I printout the file.lasterror contents as I go through each line of a created file.  When you run the snippet you'll see that it only prints out as blank even when I read past the end of the file.  When the value that is in the variable "Contents" becomes blank is when the routine stops reading.  This tells me that you can't use File.LastError to detect EOF.  You can use blank.

    Jricestk

    For x=1 To 3
      File.WriteLine("c:\testfile.txt",x,x)
    EndFor
    x=0
    status="True"
    while status="True"
      x=x+1
      contents=File.ReadLine("c:\testfile.txt",x)
      TextWindow.WriteLine(contents)
      TextWindow.WriteLine(File.lasterror)
      If contents=""then
        status="False"
        endif
      TextWindow.WriteLine("Here")
    endwhile


    Jricestk
    • Marked as answer by litdev Tuesday, November 23, 2010 8:50 PM
    Thursday, November 18, 2010 11:44 PM
    Answerer
  • If it can't check an EOF, then what does it do?
    Saturday, November 20, 2010 5:05 PM
  • Dick033,

    Here's an example that shows what file.lasterror does.  This snippet fails on my computer because I don't have a D drive.

    status=File.copyfile("c:\test.txt","d:\test.txt")
    TextWindow.WriteLine(status)
    TextWindow.WriteLine(File.lasterror)

    The routine prints the status of a copy operation.  I have the test file in C, but I don't have a D drive.  The first writeline shows that it fails.  The second tells you why it failed.

    Jricestk


    Jricestk
    Saturday, November 20, 2010 8:19 PM
    Answerer
  • Small Basic does not throw an exception if File function fails. When File function fails small basic application handles exception and does not crash and writes the error message in File.LastError.
    Sorry My Bad English
    • Marked as answer by litdev Tuesday, November 23, 2010 8:50 PM
    Saturday, November 20, 2010 9:03 PM