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

📄 vbs349.htm

📁 VBScript 是一种脚本语言
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>
<HEAD>
<TITLE>OpenAsTextStream 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="OpenAsTextStream 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>OpenAsTextStream 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;3</A>&nbsp;<P></FONT>

</TD></TR>
</TABLE> 

<FONT SIZE=2><p>
<A HREF="vbs351.htm">See Also</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="vbs350.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, write to, or append to the file.</BLOCKQUOTE>

<H5>Syntax</H5>
<BLOCKQUOTE><i>object</i><b>.OpenAsTextStream(</b>[<i>iomode</i>, [<i>format</i>]]<b>)</b> 

<P>The <b>OpenAsTextStream</b> method syntax 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>File</b> object.</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 three constants: <b>ForReading</b>, <b>ForWriting</b>, or <b>ForAppending</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 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>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>ForWriting</B></font></TD>
		<TD ALIGN=CENTER WIDTH=10%><FONT SIZE=2>2</font></TD>
			<TD WIDTH="*"><FONT SIZE=2>Open a file for writing. If a file with the same name exists, its previous contents are overwritten.</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 <b>OpenAsTextStream</b> method provides the same functionality as the <b>OpenTextFile</b> method of the <b>FileSystemObject</b>. In addition, the <b>OpenAsTextStream</b> method can be used to write to a file.
<p>The following code illustrates the use of the <b>OpenAsTextStream</b> method:
<BLOCKQUOTE><pre><font face="Courier New" size=3>Sub TextStreamTest
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
    Dim fs, f, ts, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    fs.CreateTextFile "test1.txt"            'Create a file
    Set f = fs.GetFile("test1.txt")
    Set ts = <font color="#FF0000">f.OpenAsTextStream(</font>ForWriting<font color="#FF0000">,</font> TristateUseDefault<font color="#FF0000">)</font>
    ts.Write "Hello World"
    ts.Close
    Set ts = <font color="#FF0000">f.OpenAsTextStream(</font>ForReading<font color="#FF0000">,</font> TristateUseDefault<font color="#FF0000">)</font>
    s = ts.ReadLine
    MsgBox s
    ts.Close
End Sub</font></pre>
</BLOCKQUOTE></BLOCKQUOTE>
<hr noshade size=1>
<FONT SIZE=2>
<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 + -