Hitachi

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


8.5.7 TextWrite (write data to a text file)

Purpose

Writes data to a text file.

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

Syntax
TextWrite (FileId, Data, [NewLine] [, Position])
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 ReadOnly as the file access mode in the TextOpen command.

Data

Specify the write data as a character string or as a variable that stores this value.

NewLine

Set True to start a new line after the data is written, or False to continue on the same line.

This value is optional. If you omit this value, True is assumed.

Position

Specify the read/write position relative to the beginning of the file (0). Write a number or a variable that stores this value. You can specify a value in the range from 0 to 2,147,483,647 (units: bytes).

This value is optional. If you omit this value, the current read/write position is assumed.

For large files, you cannot specify 2 gigabytes or a larger value as the write position.

Description

The TextWrite command writes data to the text file specified by file ID, starting at the current read/write position or at a specified read/write position. The command returns True on successful execution, or False if an error occurs.

On successful execution, the current read/write position is the next line if you specified True in NewLine, or the end of the written data if you specified False.

Important note

If you specify WriteOnly or ReadWrite in the Mode of the TextOpen command for an existing file and then execute the TextWrite command, the TextWrite command overwrites as many characters as are specified. If the number of characters to be output (including linefeed codes) is less than the number in the existing file, all the excess characters contained in the file before the file was opened remain in the file.

Example

The script below creates the text file Loging.txt in the executable folder.

  • Script file

  Dim  file1
  file1 = TextOpen ( _BIN_+"Loging.txt" ,Create )
  If  file1 = 0  Then
    MessageBox ( _BIN_+"Failed to open Loging.txt" ,OK )
  Else
    TextWrite ( file1 ,"<< " + _COMP_ + " / " +  _USER_ + " >>" )
    TextWrite ( file1 , Date + " " + Time + " " ,False )
    TextWrite ( file1 ,"Start script execution" )
    TextClose ( file1)
  End
  • Execution result (contents of Loging.txt)

  << COMP01 / USER01 >>
  2011/08/31 11:57:22 Start script execution
JP1/Script version

Supported from JP1/Script 05-00.