OpenAsTextStream Method

 

Description

 

Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.

 

PowerBASIC Syntax

 

METHOD OpenAsTextStream ( _

OPTIONAL BYVAL IOMode AS LONG, _

OPTIONAL BYVAL nFormat AS LONG _

) AS ITextStream

 

Arguments

 

IOMode

LONG. Optional. Indicates input/output mode. Can be one of three constants: ForReading, ForWriting, or ForAppending.

nFormat

LONG. Optional. One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.

 

Settings

 

The IOMode argument can have any of the following settings:

 

Constant

Value

Description

ForReading

1

Open a file for reading only. You can't write to this file.

ForWriting

2

Open a file for writing. If a file with the same name exists, its previous contents are overwritten.

ForAppending

8

Open a file and write to the end of the file.

 

The format argument can have any of the following settings:

 

Constant

Value

Description

TristateUseDefault

-2

Opens the file using the system default.

TristateTrue

-1

Opens the file as Unicode.

TristateFalse

 0

Opens the file as ASCII.

 

Remarks

 

The OpenAsTextStream method provides the same functionality as the OpenTextFile method of the FileSystemObject. In addition, the OpenAsTextStream method can be used to write to a file.

 

Example [PowerBASIC]

 

#INCLUDE "windows.inc"

#INCLUDE "scrrun.inc"

 

DIM fso AS IFileSystem

DIM pFile AS IFile

DIM pStm AS ITextStream

 

' Create an instance of the FileSystemObject

fso = NEWCOM "Scripting.FileSystemObject"

' Get a reference to the IFile interface

pFile = fso.GetFile(UCODE$("C:\MyPath\MyFile.txt"))

' Open the file as text stream

pStm = pFile.OpenAsTextStream(%IOMode_ForReading)

 

Valid XHTML 1.0 Transitional