【分享】WINCC 读写文本文件
Dim objFSO
Dim objTextFile
Dim strTEXT
Set objFSO = CreateObject("Scripting.FileSystemObject")
'检察文件是否存在
If objFSO.FileExists("C:WINCC_TEXT_TEST.txt")=True Then
MsgBox "文本文件已经存在",65536,"提示"
' ------------------------------------------------------
'写入数据
Set objTextFile = objFSO.OpenTextFile("C:WINCC_TEXT_TEST.txt",8,True)
MsgBox "打开文件成功"
objTextFile.WriteLine("欢迎领导视察工作!")
MsgBox "写入成功"
objTextFile.Close
'读取数据
Set objTextFile = objFSO.OpenTextFile("C:WINCC_TEXT_TEST.txt",1)
strTEXT = objTextFile.ReadALL
MsgBox strTEXT
objTextFile.Close
MsgBox "读取完毕!",65536,"提示"
' 清除数据
Set objTextFile = objFSO.OpenTextFile("C:WINCC_TEXT_TEST.txt",2)
Do Until objTextFile.AtEndOfStream
objTextFile.Write""
Loop
objTextFile.Close
MsgBox "清除数据完毕!",65536,"提示"
' ------------------------------------------------------
Else
'自动创建文件
Set objFile =objFSO.CreateTextFile("C:WINCC_TEXT_TEST.txt")
MsgBox "文本文件创建成功",64,"提示"
End If