Hitachi

JP1 Version 11 JP1/Script Description and Reference (For Windows Systems)


8.5.6 TextRead (read one line of data from a text file)

Purpose

Reads one line of data from a text file.

In JP1/Script 07-50 or later, the command supports large files.

Syntax
TextRead (FileId, Buff)
Arguments
FileId

Specify the file ID as a number or as a variable that stores this value.

This file ID is the execution result returned by the TextOpen command. Specify a value other than WriteOnly as the file access mode in the TextOpen command.

Buff

Specify a variable for storing the line of data read from the file. The data is truncated if it exceeds 1,024 bytes.

Description

The TextRead command reads one line of data from the text file specified by file ID, starting at the current read/write position, and stores the data in the specified variable. The command returns True on successful execution, or False if an error occurs.

On successful execution, the next line becomes the current read/write position.

If the end of the file is reached, the command returns False as the execution result and sets the same value as the _ERR_EOF_ reserved variable in the _RTN_ reserved variable. The execution control does not jump to the label specified in the On Error statement.

Important note

When the TextRead command detects the end of file, JP1/Script treats it as an error in the same manner as an error during command execution. In such a case, the error is recorded in the execution trace log even if script processing terminates normally. On the Trace Viewer, this event is displayed as an abnormal termination. Ignore any EOF detection error on the TextRead command.

Additionally, the variable for receiving a line of data read by the TextRead command contains the previous value. Therefore, after detection of EOF, do not use any process that expects the variable to contain no value.

Example
' The following script reads lines of data one by one from
' the Loging.txt text file in the execution folder.
Dim file1, buff1, readRtn
 
On Error GoTo ErrorBranch
  file1 = TextOpen (_BIN_+"Loging.txt", ReadOnly)
  TextRead (file1, buff1)
  readRtn = _RTN_
  While readRtn <> _ERR_EOF_
    MessageBox (buff1)
    TextRead (file1, buff1)
    readRtn = _RTN_
  End
 
TextClose (file1)
Exit (0)
 
ErrorBranch:
  MessageBox (_BIN_+"Operation on the Loging.txt file failed", OK)
  TextClose (file1)
  Exit (-1)
JP1/Script version

Supported from JP1/Script 05-00.