到目前为止,下面的代码就是我正在使用的代码。它运行在西门子HMI(IPC477d)上,但是当我测试脚本时,我得到的错误是
HmiRTm.exe [5984]中发生了未处理的异常('错误的文件名或编号')。
我想知道我的代码中的错误在哪里。
代码行SmartTags(...)
是HMI内用于处理PLC标签的软件的一部分。所以它只是PLC代码中的一个变量。变量本身将始终是字符串值。我不知道这是否很重要,但我想我会把那个扔给那里的人,想知道这行代码发生了什么。
Sub CreateTXTReport()
'Tip:
' 1. Use the <CTRL+SPACE> or <CTRL+I> shortcut to open a list of all objects and functions
' 2. Write the code using the HMI Runtime object.
' Example: HmiRuntime.Screens("Screen_1").
' 3. Use the <CTRL+J> shortcut to create an object reference.
'Write the code as of this position:
Dim TT,DT
'If(SmartTags("
TT = FormatDateTime(Time,3)
DT = FormatDateTime(Date,0)
Dim fso, MYfile, strFileName, strFullName, strPath
strPath = "D:\txtFiles"
strFileName = "BatchFile_" & DT & "_" & TT & ".txt"
SmartTags("BatchFileName") = strFileName
Const forWriting=1,forReading=2, forAppending=8
Set fso = CreateObject("Scripting.FileSystemObject")
strFullName = fso.BuildPath(strPath,strFileName)
'If (fso.FileExists("D:\txtFiles\" & strFileName)) = True Then
'Set MYfile = fso.OpenTextFile("D:\txtFiles\" & strFileName, forAppending, True)
'Else
'Set MYfile = fso.CreateTextFile("D:\txtFiles\" & strFileName, forWriting, True)
'MYfile.WriteLine DT & "," & TT & "," & "BatchFile"
'End If
If (fso.FileExists(strFullName)) = True Then
Set MYfile = fso.OpenTextFile(strFullName, forAppending, True)
Else
Set MYfile = fso.CreateTextFile(strFullName, forWriting, True)
MYfile.WriteLine DT & "," & TT & "," & "BatchFile"
End If
MYfile.WriteLine(SmartTags("ReportVariable"))
MYfile.Close
PrintReport("BatchFile_" & DT & "_" & TT & ".txt" )
End Sub