时间烙下的记忆
交给时间
VBS读写txt
上一篇 /
下一篇 2009-08-31 16:06:28
/ 个人分类:VBS
读文件:
------------------------------------------------------------
Option Explicit
'表示所有的变量先声明,后使用。如果模块中使用了 Option Explicit,则必须使用 Dim、Private、Public、ReDim 或 Static 语句来显式声明所有的变量。如果使用了未声明的变量名在编译时间会出现错误。使用 Option Explicit 可以避免在键入已有变量时出错,在变量的范围不是很清楚的代码中使用该语句可以避免混乱。
Const ForReading=1 '
Const ForWriting=2
Const ForAppending=8
Dim fso,file,msg
Set fso=CreateObject("Scripting.FileSystemObject")
Set file=fso.OpenTextFile("F:\VBS\Read.txt",ForReading,True)
Do While Not file.AtEndOfStream
msg=file.ReadLine
MsgBox msg
Loop
file.Close
set file=Nothing
set fso=Nothing
写文件:
----------------------------------------------
Option Explicit '表示所有的变量先声明,后使用。如果模块中使用了 Option Explicit,则必须使用 Dim、Private、Public、ReDim 或 Static 语句来显式声明所有的变量。如果使用了未声明的变量名在编译时间会出现错误。使用 Option Explicit 可以避免在键入已有变量时出错,在变量的范围不是很清楚的代码中使用该语句可以避免混乱。
Const ForReading=1 '
Const ForWriting=2
Const ForAppending=8
Dim fso,file,msg
Set fso=CreateObject("Scripting.FileSystemObject")
Set file=fso.OpenTextFile("F:\VBS\Write.txt",ForWriting,True)
file.WriteLine("I am not happy today,and you?")
file.WriteLine("Please be happy,my love!!!")
file.Close
set file=Nothing
set fso=Nothing
收藏
举报
TAG: