WINCC中用VBS脚本写文本文件问题

我想用winCC中的VBS脚本向一个文本文件中写变量,西门子也提供了一个例程:
Dim fso, MyFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)

MyFile.WriteLine("This is a test.")

MyFile.Close

但是这个脚本是每次用建一个新的文本文件去覆盖前一个文本文件,不能实现在同一个文本文件中逐行写入变量,请问这个要求怎么实现啊.

最佳答案

Dim fso, MyFile
Const ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
MsgBox("aaa")
Set MyFile = fso.OpenTextFile("d:\testfile.txt",ForAppending,True)
MsgBox("bbb")
MyFile.WriteLine("This is a test.")
MsgBox("ccc")
MyFile.Close
本人测试通过。

提问者对于答案的评价:
thank you!

原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc266806.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2019年6月11日
下一篇 2019年6月11日

相关推荐