⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vbs352.htm

📁 VBScript 是一种脚本语言
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>
<HEAD>
<TITLE>OpenTextFile Method</TITLE> 
<META NAME="CATEGORY" CONTENT="Language Reference"> 
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
<META NAME="PRODUCT" CONTENT="Visual Basic Scripting Edition">
<META NAME="TECHNOLOGY" CONTENT="SCRIPTING">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="OpenTextFile Method">
</HEAD>

<BODY BGCOLOR=FFFFFF LINK=#0033CC>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR VALIGN=TOP><TD WIDTH=360>
<FONT SIZE=1 COLOR=#660033>Microsoft&#174; Visual Basic&#174; Scripting Edition</FONT><BR>
<FONT SIZE=5 COLOR=#660033><B>OpenTextFile Method</B></FONT>

</TD>
<TD ALIGN=RIGHT>
<FONT SIZE=2>&nbsp;<A HREF="vbstoc.htm">Language&nbsp;Reference</A>&nbsp;<BR>
<A HREF="vbs16.htm">Version&nbsp;2</A>&nbsp;<P></FONT>
</TD></TR>
</TABLE>

<FONT SIZE=2><P>
<A HREF="vbs354.htm">See Also</A>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="vbs353.htm">Applies To</A></FONT>


<HR noshade SIZE=1>
<H5>Description</H5>
<BLOCKQUOTE>Opens a specified file and returns a <b>TextStream</b> object that can be used to read from or append to the file.</BLOCKQUOTE>

<H5>Syntax</H5>
<BLOCKQUOTE>
	<i>object</i><b>.OpenTextFile(</b><i>filename</i>[<b>,</b> <i>iomode</i>[<b>,</b> <i>create</i>[<b>,</b> <i>format</i>]]]<b>)</b><P>
The <b>OpenTextFile</b> method has these parts:<P>

<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
	<TD><FONT SIZE=2><b>Part</b></FONT></TD>
		<TD><FONT SIZE=2><b>Description</b></FONT></TD></TR>
<TR VALIGN=TOP>
	<TD><FONT SIZE=2><i>object</i></FONT></TD>
		<TD><FONT SIZE=2>Required. Always the name of a <b>FileSystemObject</b>.</FONT></TD></TR>
<TR VALIGN=TOP>
	<TD><FONT SIZE=2><i>filename</i></FONT></TD>
		<TD><FONT SIZE=2>Required. <A HREF="vbs0.htm#defStringExpression">String expression</A> that identifies the file to open.</FONT></TD></TR>
<TR VALIGN=TOP>
	<TD><FONT SIZE=2><i>iomode</i></FONT></TD>
		<TD><FONT SIZE=2>Optional. Indicates input/output mode. Can be one of two constants, either <b>ForReading</b> or <b>ForAppending</b>.</FONT></TD></TR>
<TR VALIGN=TOP>
	<TD><FONT SIZE=2><i>create</i></FONT></TD>
		<TD><FONT SIZE=2>Optional. Boolean value that indicates whether a new file can be created if the specified <i>filename</i> doesn't exist. The value is <b>True</b> if a new file is created; <b>False</b> if it isn't created. The default is <b>False</b>.</FONT></TD></TR>
<TR VALIGN=TOP>
	<TD><FONT SIZE=2><i>format</i></FONT></TD>
		<TD><FONT SIZE=2>Optional. One of three <b>Tristate</b> values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.
</FONT></TD></TR>
</TABLE>
</BLOCKQUOTE>

<H5>Settings</H5>
<BLOCKQUOTE>
The <i>iomode</i> argument can have either of the following settings:<p>
<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
	<TD WIDTH=15%><FONT SIZE=2><b>Constant</b></font></TD>
		<TD WIDTH=10%><FONT SIZE=2><b>Value</b></font></TD>
			<TD WIDTH="*"><FONT SIZE=2><b>Description</b></font></TD></TR>
<TR VALIGN=TOP>
	<TD WIDTH=15%><FONT SIZE=2><B>ForReading</B></font></TD>
		<TD ALIGN=CENTER WIDTH=10%><FONT SIZE=2>1</font></TD>
			<TD WIDTH= "*"><FONT SIZE=2>Open a file for reading only. You can't write to this file.</font></TD></TR>

<TR VALIGN=TOP>
	<TD WIDTH=15%><FONT SIZE=2><B>ForAppending</B></font></TD>
		<TD ALIGN=CENTER WIDTH=10%><FONT SIZE=2>8</font></TD>
			<TD WIDTH="*"><FONT SIZE=2>Open a file and write to the end of the file.</font></TD></TR>
</TABLE>

The <i>format</i> argument can have any of the following settings:<p>

<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
	<TD WIDTH=15%><FONT SIZE=2><b>Constant</b></font></TD>
		<TD WIDTH=10%><FONT SIZE=2><b>Value</b></font></TD>
			<TD WIDTH="*"><FONT SIZE=2><b>Description</b></font></TD></TR>
<TR VALIGN=TOP>
	<TD WIDTH=15%><FONT SIZE=2><b>TristateUseDefault</b></font></TD>
		<TD ALIGN=CENTER WIDTH=10%><FONT SIZE=2>-2</font></TD>
			<TD WIDTH="*"><FONT SIZE=2>Opens the file using the system default.</font></TD></TR>
<TR VALIGN=TOP>
	<TD WIDTH=15%><FONT SIZE=2><b>TristateTrue</b></font></TD>
		<TD ALIGN=CENTER WIDTH=10%><FONT SIZE=2>-1</font></TD>
			<TD WIDTH= "*"><FONT SIZE=2>Opens the file as Unicode.</font></TD></TR>

<TR VALIGN=TOP>
	<TD WIDTH=15%><FONT SIZE=2><b>TristateFalse</b></font></TD>
		<TD ALIGN=CENTER WIDTH=10%><FONT SIZE=2>&nbsp;0</font></TD>
			<TD WIDTH="*"><FONT SIZE=2>Opens the file as ASCII.</font></TD></TR>
</TABLE>
</BLOCKQUOTE>

<H5>Remarks</H5>
<BLOCKQUOTE>
The following code illustrates the use of the <b>OpenTextFile</b> method to open a file for appending text:
<BLOCKQUOTE><PRE><FONT FACE="Courier New" SIZE=3>Sub OpenTextFileTest
  Const ForReading = 1, ForWriting = 2, ForAppending = 3
  Dim fs, f
  Set fs = CreateObject("Scripting.FileSystemObject")
  Set f = <FONT COLOR="#FF0000">fs.OpenTextFile(</FONT>"c:\testfile.txt"<FONT COLOR="#FF0000">,</FONT> ForAppending<FONT COLOR="#FF0000">,</FONT>TristateFalse<FONT COLOR="#FF0000">)</FONT>
  f.Write "Hello world!"
  f.Close
End Sub
</FONT></PRE></BLOCKQUOTE>
</BLOCKQUOTE>
<hr noshade size=1>
<p align=center><em><a href="../../common/colegal.htm">&copy; 1997 by Microsoft Corporation. All rights reserved.</a></em></p> 
</FONT></FONT></BODY></HTML>










































































⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -