Home THE HYPERCARD CENTER

HyperTalk Reference
Home » HyperTalk Reference » Commands

Note: This is a work in progress and will be formatting errors. Read more about the project on the home page.

read

read from file fileName [at [-] ¬
integer] {for posInteger |until char}
The read command reads data from a file. (You must have already opened the file with the open file command.) Read places the data into the local variable it.

Reading of a newly opened file starts from the beginning of the file, or optionally at character integer. If you use the form at -integer, reading starts at integer characters from the end of

the file. Subsequent reads continue from the last point read.

Read
continues until it has read the specified number of characters or it reaches the named ASCII character (which can be specified as a constant: colon, comma, end, eof, formfeed, quote, return, space, or tab).

All characters count as data, including return characters at the end of lines, spaces, and tab characters.


Examples

read from file "Data" until Z -- read until first Z  
read from file "Data" until tab  
read from file "Data" until return -- read one line
read from file "Data" until end -- read until the end of the file
read from file "Data" for 100 -- read 100 bytes
read from file "Data" at 200 for 100 -- read 100 bytes ¬
                starting at the 200th character in the file
read from file "Data" at -200 for 100 -- read 100 bytes ¬
                starting at the 200th character from the end of the file
 
read from file "My Data"
-- This function asks for the name of a text file and reads it.
-- You might use it as follows: 

-- put readFile() into myInfo

-- Note that variables can hold unlimited amounts of information
-- while fields can only hold 30k.

function readFile
  answer file "Read what text file?" of type text
  if (it is empty) or (it is "Cancel") then return empty
  put it into theFileName
  open file theFileName
  repeat forever
    read from file theFileName for 16384
    if it is empty then exit repeat
    put it after theData
  end repeat
  close file theFileName
  return theData
end readFile

Placeholders

fileName
An expression that evaluates to a text string that is also a valid Macintosh filename.

For example:

"my stack"
"HD20:Wally's Stacks:my stack"
"my file alias"


integer
An expression that evaluates to a positive or negative integer or to zero. For example:

3
18 - 100
-(3 * sum(1,3,4,5)) + 39
In AppleScript, integer is a value class.

posInteger
An expression that evaluates to a positive integer.

For example:
3
67 mod 13
the number of bg fields
the number of backgrounds
the number of cards div 2
See also: background, bkgnd, button, card, chunk, field, menu, and menuItem

char
An expression that yields a single character.

For example:

"a"
return
tab
numToChar(13)


Related Topics

« put | HyperTalk Reference | reply »


Version 0.7b1 (March 24, 2022)

Made with Macintosh

Switch to Modern View

Home
The HyperCard Center
HyperTalk Reference
Home » HyperTalk Reference » Commands

Note: This is a work in progress and will be formatting errors. Read more about the project on the home page.

read

read from file fileName [at [-] ¬
integer] {for posInteger |until char}
The read command reads data from a file. (You must have already opened the file with the open file command.) Read places the data into the local variable it.

Reading of a newly opened file starts from the beginning of the file, or optionally at character integer. If you use the form at -integer, reading starts at integer characters from the end of

the file. Subsequent reads continue from the last point read.

Read
continues until it has read the specified number of characters or it reaches the named ASCII character (which can be specified as a constant: colon, comma, end, eof, formfeed, quote, return, space, or tab).

All characters count as data, including return characters at the end of lines, spaces, and tab characters.


Examples

read from file "Data" until Z -- read until first Z  
read from file "Data" until tab  
read from file "Data" until return -- read one line
read from file "Data" until end -- read until the end of the file
read from file "Data" for 100 -- read 100 bytes
read from file "Data" at 200 for 100 -- read 100 bytes ¬
                starting at the 200th character in the file
read from file "Data" at -200 for 100 -- read 100 bytes ¬
                starting at the 200th character from the end of the file
 
read from file "My Data"
-- This function asks for the name of a text file and reads it.
-- You might use it as follows: 

-- put readFile() into myInfo

-- Note that variables can hold unlimited amounts of information
-- while fields can only hold 30k.

function readFile
  answer file "Read what text file?" of type text
  if (it is empty) or (it is "Cancel") then return empty
  put it into theFileName
  open file theFileName
  repeat forever
    read from file theFileName for 16384
    if it is empty then exit repeat
    put it after theData
  end repeat
  close file theFileName
  return theData
end readFile

Placeholders

fileName
An expression that evaluates to a text string that is also a valid Macintosh filename.

For example:

"my stack"
"HD20:Wally's Stacks:my stack"
"my file alias"


integer
An expression that evaluates to a positive or negative integer or to zero. For example:

3
18 - 100
-(3 * sum(1,3,4,5)) + 39
In AppleScript, integer is a value class.

posInteger
An expression that evaluates to a positive integer.

For example:
3
67 mod 13
the number of bg fields
the number of backgrounds
the number of cards div 2
See also: background, bkgnd, button, card, chunk, field, menu, and menuItem

char
An expression that yields a single character.

For example:

"a"
return
tab
numToChar(13)


Related Topics

« put | HyperTalk Reference | reply »

Version 0.7b1 (March 24, 2022)

Made with Macintosh

Switch to Retro View