{"identifier":45683,"topic":"Commands","name":"read","text":"<code><pre>read from file <i>fileName<\/i> [at [-] \u00ac\n<i>integer<\/i>] {for <i>posInteger<\/i> |until <i>char<\/i>}\n<\/pre><\/code> The<code> read <\/code>command reads data from a file. (You must have already opened the file with the<code> open file <\/code>command.) <code> Read <\/code>places the data into the local variable<code> it<\/code>. <br><br>\n\n Reading of a newly opened file starts from the beginning of the  file, or optionally  <code>at <\/code>character <i><code>integer<\/i>. <\/code>If you use the form <code>at -<i>integer<\/i><\/code>, reading starts at <i><code>integer<\/i> <\/code>characters from the end of <br>\n<br>\nthe file. Subsequent reads continue from the last point read.<code> <br><br>\n\n Read <\/code>continues until it has read the specified number of characters or it reaches the named ASCII character (which can be specified as a constant: <code> colon, comma, end<\/code>,<code> eof<\/code>,<code> formfeed<\/code>,<code> quote<\/code>,<code> return<\/code>,<code> space<\/code>,<code> <\/code>or<code> tab<\/code>). <br><br>\n\n All characters count as data, including return characters at the end of lines, spaces, and tab characters. <br>\n","related":{"32483":"close","41778":"open","41996":"open file","44420":"print","51002":"write"},"examples":"read from file \"Data\" until Z -- read until first Z  \nread from file \"Data\" until tab  \nread from file \"Data\" until return -- read one line\nread from file \"Data\" until end -- read until the end of the file\nread from file \"Data\" for 100 -- read 100 bytes\nread from file \"Data\" at 200 for 100 -- read 100 bytes \u00ac\n                starting at the 200th character in the file\nread from file \"Data\" at -200 for 100 -- read 100 bytes \u00ac\n                starting at the 200th character from the end of the file\n \nread from file \"My Data\"\n-- This function asks for the name of a text file and reads it.\n-- You might use it as follows: \n\n-- put readFile() into myInfo\n\n-- Note that variables can hold unlimited amounts of information\n-- while fields can only hold 30k.\n\nfunction readFile\n  answer file \"Read what text file?\" of type text\n  if (it is empty) or (it is \"Cancel\") then return empty\n  put it into theFileName\n  open file theFileName\n  repeat forever\n    read from file theFileName for 16384\n    if it is empty then exit repeat\n    put it after theData\n  end repeat\n  close file theFileName\n  return theData\nend readFile","demo":"","debug":{"9":["read from file fileN"],"10":["the file. Subsequent"]}}