Hitachi

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


8.5.4 TextOpen (open a text file)

Purpose

Opens a text file.

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

Syntax
TextOpen (FilePath [, Mode])
Arguments
FilePath

Write the full path of the text file as a character string or as a variable that stores this value.

If you omit the extension, .TXT is automatically appended to the file name. However, in JP1/Script 06-00 and later versions, if you specify a file name ending with the extension period (.), the file is regarded as having no extension.

Mode

Specify how to open the file as one of the following values:

Value

Meaning

Create

Create a new file unconditionally.

ReadOnly

Open the file in read-only mode.

WriteOnly

Open the file in write-only mode.

ReadWrite

Open the file in read/write mode.

If you specify ReadOnly in Mode, the file will be accessed in shared mode. If you specify Create, WriteOnly, or ReadWrite, the file will be locked when accessed.

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

Description

The TextOpen command opens a specified text file. The command returns the file ID on successful execution, or 0 if an error occurs.

At successful execution, the current read/write position is the beginning of the file (0).

Notes
  • Take care when specifying a file in the folder set in the environment variable ProgramFiles (normally the Program Files folder on the system drive) or WinDir (normally the Windows folder on the system drive). For details, see 1.8.2 Command behavior.

  • You can configure access permissions when creating a text file. In the following registry key, set the access permissions beforehand:

Registry key

HKEY_LOCAL_MACHINE\SOFTWARE\Hitachi\JP1/Script\SPTX\Option

Value name

SecurityAttributesSucceed

Value datatype

REG_DWORD

Value

0: Access permissions are not set.

1: Access permissions are set to "Inherit access permissions from parent folders".

2: Access permissions are set to "Everyone: Full control".

If no value is set, or a value other than those above is set, the setting defaults to 0.

When the setting takes effect

The setting takes effect the next time the script file is executed.

Example
' Read Loging.txt, and display its contents in a dialog box.
Dim file1
file1 = TextOpen (_BIN_+"Loging.txt", ReadOnly)
If file1 = 0 Then
  MessageBox (_BIN_+"Failed to open Loging.txt", OK)
Else
  Dim buff1
  If TextRead (file1, buff1) Then
    MessageBox (buff1, OK)
  End
 
  TextClose (file1)
End
JP1/Script version

Supported from JP1/Script 05-00.