我有一个工作脚本,它读取 WinCC DB 并将数据写入具有两列(1 个时间标签和 1 个值)的 CSV 文件。
path = "C:\HMI\Report\Report.csv"
'creating csv file
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(path) Then
fso.DeleteFile(path)
End If
fso.CreateTextFile(path)
Set f = fso.GetFile(path)
Const ForWriting = 2
Const TristateUseDefault = -2
Set ts = f.OpenAsTextStream(ForWriting,TristateUseDefault)
'''''''''''''''''''
'connection to SQL
Dim Pro 'Provider
Dim DSN 'Data Source Name
Dim DS 'Data Source
Dim ConnString 'Connection String
Dim MachineNameRT 'Name of the PC from WinCC-RT
Dim DSNRT 'Data Source Name from WinCC-RT
Dim Conn 'Connection to ADODB
Dim RecSet 'RecordSet
Dim Command 'Query
Dim CommandText 'Command-Text
Set MachineNameRT = HMIRuntime.Tags("@LocalMachineName")
Set DSNRT = HMIRuntime.Tags("@DatasourceNameRT")
pro="Provider=WinCCOLEDBProvider.1;"
DSN="Catalog=" & DSNRT.Read & ";"
DS="Data Source=.\WinCC" ' & MachineNameRT.Value & "\WinCC"
ConnString = Pro + DSN + DS
Set Conn = CreateObject("ADODB.Connection")
Conn.ConnectionString = ConnString
Conn.CursorLocation = 3
Conn.Open
CommandText="Tag:R,(ProductionTags\Temperature1),'" & StartArchive & "','" & StopArchive & "'"
'Create the recordset, read the records and set to first redcordset:
Set Command = CreateObject("ADODB.Command")
Command.CommandType = 1
Set Command.ActiveConnection = Conn
Command.CommandText=CommandText
Set RecSet = Command.Execute
RecSet.MoveFirst
Do While Not RecSet.EOF
ts.WriteLine (RecSet.Fields("TimeStamp").Value & ";" & RecSet.Fields("RealValue").Value) '<-that's the line in question
RecSet.MoveNext
Loop
' Close all
ts.Close
RecSet.Close
Set RecSet=Nothing
Set Command = Nothing
conn.Close
Set Conn = Nothing
Set fso = Nothing
Set f = Nothing
Set ts = Nothing
我想在 4 或 6 列中写入 1 个时间标签和 3 个值,或 3 个时间标签和 3 个值。
我想将查询更改为
CommandText="Tag:R,(ProductionTags\Temperature1;ProductionTags\Temperature2;ProductionTags\Temperature3),'" & StartArchive & "','" & StopArchive & "'"
但我不明白如何为 Writeline 编写参数以获取循环中的值以使其成为 4 或 6 列。