OpenTextFile

来源:互联网 发布:域名不以封疆 编辑:程序博客网 时间:2024/06/06 09:28

Visual Basic for Applications Reference

Visual Studio 6.0
72 out of 190 rated this helpful Rate this topic

OpenTextFile Method

See Also    Example    Applies To    Specifics

Description

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

Syntax

object.OpenTextFile(filename[, iomode[, create[, format]]])

The OpenTextFile method has these parts:

PartDescriptionobjectRequired. Always the name of a FileSystemObject.filenameRequired. String expression that identifies the file to open.iomodeOptional. Indicates input/output mode. Can be one of two constants, either ForReading or ForAppending.createOptional. 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. The default is False.formatOptional. 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 either of the following settings:

ConstantValueDescriptionForReading1Open a file for reading only. You can't write to this file.ForAppending8Open a file and write to the end of the file.

The format argument can have any of the following settings:

ConstantValueDescriptionTristateUseDefault2Opens the file using the system default.TristateTrue1Opens the file as Unicode.TristateFalse  0Opens the file as ASCII.

Remarks

The following code illustrates the use of the OpenTextFile method to open a file for appending text:

Sub OpenTextFileTest    Const ForReading = 1, ForWriting = 2, ForAppending = 3    Dim fs, f    Set fs = CreateObject("Scripting.FileSystemObject")    Set f = fs.OpenTextFile("c:\testfile.txt", ForAppending,TristateFalse)    f.Write "Hello world!"    f.CloseEnd Sub
0 0
原创粉丝点击