I have a working script that reads WinCC DB and writes data into a CSV file with two columns (1 timetag and 1 value).
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
I want to write 1 timetag and 3 values, or 3 timetags and 3 values in 4 or 6 columns.
I want to change query as
CommandText="Tag:R,(ProductionTags\Temperature1;ProductionTags\Temperature2;ProductionTags\Temperature3),'" & StartArchive & "','" & StopArchive & "'"
But I can't understand how to write an argument for the Writeline to get the values in the loop to make it 4 or 6 columns.