|
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 OpenTextFile ( _
BYVAL bstrFileName AS STRING, _
OPTIONAL BYVAL IOMode AS LONG, _
OPTIONAL BYVAL bCreate AS INTEGER, _
OPTIONAL BYVAL nFormat AS LONG _
) AS ITextStream
|
Arguments
bstrFileName
|
BSTR. String expression that identifies the file to open.
|
IOMode
|
LONG. Can be one of three constants: ForReading, ForWriting, or ForAppending.
|
bCreate
|
Boolean value that indicates whether a new file can be created if the specified filename doesn't exist. The value is True if a new file is created, False if it isn't created. If omitted, a new file isn't created.
|
nFormat
|
One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII
|
Return Value
IDispatch. Reference to a ITextStream interface.
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.
|
ForAppending
|
8
|
Open a file and write to the end of the file.
|
Example [PowerBASIC]
#INCLUDE
"windows.inc"
#INCLUDE
"scrrun.inc"
DIM fso AS IFileSystem
DIM pStm AS ITextStream
DIM OutString AS STRING
' Create an instance of the FileSystemObject
fso
= NEWCOM "Scripting.FileSystemObject"
' Open the file for reading
pStm
= fso.OpenTextFile(UCODE$("C:\MyFolder\Test.txt"), %IOMode_ForReading, %FALSE,
%FALSE)
' Read the entire stream into a string
OutString = pStm.ReadAll
' Close the file
pstm.Close
|