CreateTextFile Method

 

Description

 

Creates a specified file name and returns a TextStream object that can be used to read from or write to the file.

 

PowerBASIC Syntax

 

METHOD CreateTextFile ( _

BYVAL bstrFileName AS STRING, _

OPTIONAL BYVAL bOverwrite AS INTEGER, _

OPTIONAL BYVAL bUnicode AS INTEGER _

) AS ITextStream

 

Arguments

 

bstrFileName

BSTR. String expression that identifies the file to create.

bOverwrite

Optional. Boolean value that indicates whether you can overwrite an existing file. The value is true if the file can be overwritten, false if it can't be overwritten. If omitted, existing files are not overwritten.

bUnicode

Optional. Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is true if the file is created as a Unicode file, false if it's created as an ASCII file. If omitted, an ASCII file is assumed.

 

Example [PowerBASIC]

 

#INCLUDE "windows.inc"

#INCLUDE "scrrun.inc"

 

DIM fso AS IFileSystem

DIM pFolder AS IFolder

DIM pStm AS ITextStream

 

' Create an instance of the FileSystemObject

fso = NEWCOM "Scripting.FileSystemObject"

' Get a reference to the IFolder interface

pFolder = fso.GetFolder(UCODE$("C:\MyFolder"))

' Create a text stream

pStm = pFolder.CreateTextFile(UCODE$("Test.txt"), %VARIANT_TRUE, %VARIANT_FALSE)

' Write a string and an end of line to the stream

pStm.WriteLine UCODE$("This is a test.")

' Write more strings

pStm.Write UCODE$("This is a string.")

pStm.Write UCODE$("This is a second string.")

' Write two blank lines (the first will serve as an end

' of line for the previous write instructions) and another

' string and end of line to the stream

pStm.WriteBlankLines 2

pStm.WriteLine UCODE$("This is the end line.")

' Close the file

pStm.Close

 

Valid XHTML 1.0 Transitional