VBS写文件时报“无效的过程调用或参数”
发布网友
发布时间:2022-05-23 07:39
我来回答
共1个回答
热心网友
时间:2023-10-16 23:17
' $language = "VBScript"
'*********************
' 名称: writetextfile
' 目的: 把字符串写入文件名指定的文本文件
' 如果文件不存在则创建并写入,存在则写入文件末尾
' 输入: strwritestring写入字符串,strwritefilename文件名字符串
'
'*********************
sub writetextfile(strwritestring,strwritefilename)
On Error Resume Next
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
dim fs
dim textstream_a
set fs = CreateObject("Scripting.FileSystemObject")
if Not fs.FileExists(strwritefilename) then
'***file not exist
set textstream_a = fs.CreateTextFile( strwritefilename , False)
else
'***file exist
set file_a = fs.GetFile( strwritefilename )
set textstream_a = file_a.OpenAsTextStream( ForAppending , TristateUseDefault )
End If
textstream_a.WriteLine(strwritestring)
textstream_a.Close
set textsteeam_a = nothing
Set fs = nothing
end Sub
writetextfile "我","a.txt"
rem 经测试没有出现错误,On Error Resume Next写在Sub外,只对writetextfile "我","a.txt"错误有效,对Sub内的代码是无效的