What to do
1. Create the following internal tags with project-wide updating in the WinCC Explorer:
- StartLogging (unsigned 8 bit value)
- SourcePath (Text tag 8 bit character set)
- TimeFrom (Text tag 8 bit character set)
- TimeTo (Text tag 8 bit character set)
- RetVal (signed 32 bit value)
2. Create a global VBS action and enter the tag ’StartLogging’ as tag trigger with cycle "Upon
Change".
3. Copy the following script into the action
'VBS180
Dim StartLogging
Dim SourcePath
Dim TimeFrom
Dim TimeTo
Dim RetVal
'Exit when running on client
If (Left(HMIRuntime.ActiveProject.Path, 1) = "\") Then
Exit Function
End If
'read parameters
StartLogging = HMIRuntime.Tags("StartLogging").Read
SourcePath = HMIRuntime.Tags("SourcePath").Read(1)
TimeFrom = HMIRuntime.Tags("TimeFrom").Read(1)
TimeTo = HMIRuntime.Tags("TimeTo").Read(1)
'restore or remove depends on the parameter
If (StartLogging = 1) Then
RetVal = HMIRuntime.Logging.Restore(SourcePath, TimeFrom, TimeTo, -1)
HMIRuntime.Tags("RetVal").Write RetVal, 1
HMIRuntime.Tags("StartLogging").Write 0,1
Elseif (StartLogging = 2) Then
RetVal = HMIRuntime.Logging.Remove(TimeFrom, TimeTo, -1)
HMIRuntime.Tags("RetVal").Write RetVal, 1
HMIRuntime.Tags("StartLogging").Write 0,1
End If
The action may be started on a client with the following action, for example. Please note that
parameters must be written prior to setting the control tag.
'VBS181
'set parameters
HMIRuntime.Tags("SourcePath").Write "\\client_pc\temp",1
HMIRuntime.Tags("TimeFrom").Write "2004",1
HMIRuntime.Tags("TimeTo").Write "2004",1
'start action
HMIRuntime.Tags("StartLogging").Write 1.1
VBS for Creating Procedures and Actions
1.15 Examples of VBScript
MDM - WinCC: Scripting (VBS, ANSI-C, VBA)
System Manual, 11/2008,
747