Get the App
SLTechnology News&Howtos  ›  Development  › 

The use of OpenTextFile method in VBS

Shulou Source: shulou.com Published: 2022-06-03 19:37:57 09月21日 Update

This article focuses on "the use of OpenTextFile method in VBS". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "the use of OpenTextFile method in VBS"!

Opens the specified file and returns a TextStream object that can be read, written, or appended to the file.

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

Parameter object

Required. Expected the name of the FileSystemObject object.

Filename

Required. A string expression indicating the name of the file to open.

Iomode

Optional. The input / output mode is one of the following three constants: ForReading,ForWriting, or ForAppending.

Create

Optional. The Boolean value indicating whether a new file can be created if the specified filename does not exist. True when new files are allowed to be created, False otherwise. The default is False.

Format

Optional. One of the three Tristate values indicating the format in which to open the file. If you omit this parameter, the file is opened in ASCII format.

Set up

The iomode parameter can be one of the following settings:

The constant value describes that ForReading1 opens the file in read-only mode. You cannot write to this file. ForWriting2 opens the file in write-only mode. This file cannot be read. ForAppending8 opens the file and writes at the end of the file.

< P > the format parameter can be one of the following settings:

The constant value description TristateUseDefault-2 opens the file in the system default format. TristateTrue-1 opens the file in Unicode format. TristateFalse0 opens the file in ASCII format. Description

The following code illustrates how to open a write file using the OpenTextFile method:

Sub OpenTextFileTest Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim fso, f Set fso = CreateObject ("Scripting.FileSystemObject") Set f = fso.OpenTextFile ("c:\ testfile.txt", ForWriting, True) f.Write "Hi, hello!" F.Close so far, I believe you have a deeper understanding of "the use of the OpenTextFile method in VBS". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: File method format parameter object three content name for this numerical value pattern learning practical deeper code hello interest character string practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft NVidia MariaDB Linux