locked
Program help - Why does this not work? RRS feed

  • Question

  • I have two text files in the program directory, when I try to use the variable name read from first file to recall the text read on the second file, it will not read the text line 1 of the second file. However, when I type out the path (shown on line 4 below) it reads it fine. I can't see what's wrong, I have done this in the past with success.

    Path = Program.Directory
    ItemNo1  = File.ReadContents  (Path + "\Last Item.txt")
    ItemNo = File.ReadLine (Path + "\" + ItemNo1 + ".txt", 1)
     'ItemNo = File.ReadLine (Path + "\1st Item.txt", 1)
     TextWindow.Write (ItemNo1 )
     TextWindow.Write (ItemNo  )

    Monday, August 8, 2011 7:38 PM

Answers

  • A CRLF (new line) in your "Last Item.txt" file will cause this to fail

    Change

    ItemNo1  = File.ReadContents  (Path + "\Last Item.txt")

    to

    ItemNo1  = File.ReadLine  (Path + "\Last Item.txt", 1)

    or find some other way to make sure that there is no 'extra' CRLF
    • Marked as answer by SFC-P33A Monday, August 8, 2011 8:49 PM
    Monday, August 8, 2011 8:37 PM

All replies

  • A CRLF (new line) in your "Last Item.txt" file will cause this to fail

    Change

    ItemNo1  = File.ReadContents  (Path + "\Last Item.txt")

    to

    ItemNo1  = File.ReadLine  (Path + "\Last Item.txt", 1)

    or find some other way to make sure that there is no 'extra' CRLF
    • Marked as answer by SFC-P33A Monday, August 8, 2011 8:49 PM
    Monday, August 8, 2011 8:37 PM
  • Thank you Nearly Unique, that was it, Actually when I looked at my other programs I did use file.readline and not file.readcontents
    Monday, August 8, 2011 8:48 PM