VBA - New Online Container in zenOn 6.22 (BulkMode)
With zenOn 6.22 SP0 a new kind of Variable Online Container has been implemented.
Using this "Bulk Mode" a faster start of the zenOn Runtime can be guaranteed in comparison to the "normal" Variable Online Container.
With the "normal" Variable Online Container for every new value of the variable a Change Event is fired -> Private Sub zOLV_VariableChange(ByVal obVar As IVariable)
So when starting the zenOn Runtime this event will be fired as often as variables have been defined in the Online Container.
With the "Bulk Mode" -> Private Sub zOLV_VariableBulkChange(....) an array with the changed variables will be returned.
See below a VBA sample how to do.
-> if you do not want to add all variables to the Container it is possible to add only those variables which do have a certain pattern within the variablename. I.e. you have 50 variables with the variablename
- MyS7TCPIP_VAR_1
- MyS7TCPIP_VAR_2
.....
- MyS7TCPIP_VAR_50
VBA Code:
Option Explicit
Dim WithEvents zOLV As OnlineVariable
Dim strVariables() As String
Const strVarNamePart As String = "MyS7TCPIP_VAR_" 'Pattern of the VariableName
Private Sub Project_Active()
Dim iVar As Integer
' '#######################################
' 'this would add all variables existing in the project to the Online Container (array)
' '#######################################
' 'create array of all existing variables within the project
' ReDim strVariables(thisProject.Variables.Count)
' For iVar = 0 To thisProject.Variables.Count - 1
' strVariables(iVar) = thisProject.Variables.Item(iVar).Name
' Next iVar
' '#######################################
'#######################################
'this would add all variables in the project to the Online Container (array)
'-> which matches the given pattern in the VariableName
'#######################################
ReDim strVariables(thisProject.Variables.Count)
For iVar = 0 To thisProject.Variables.Count - 1
'search for the pattern within the VariableName (strVarNamePart)
If InStr(1, thisProject.Variables.Item(iVar).Name, strVarNamePart) <> 0 Then
strVariables(iVar) = thisProject.Variables.Item(iVar).Name
End If
Next iVar
'#######################################
'get/create onlinevariable - container
Set zOLV = thisProject.OnlineVariables.Item("myOLV")
If zOLV Is Nothing Then
Set zOLV = thisProject.OnlineVariables.CreateOnlineVariables("myOLV")
End If
'add variables (array) as bulk to the online container
zOLV.AddBulk strVariables()
'activate BULK Mode
zOLV.ActivateBulkMode
'activate VariableBulkChange - Event
zOLV.Define
End Sub
'#######################################
'to react on the VariableBulkChange for a specific variable it would be necessary to run through the array
'if a reaction on a Variable Change should be available it is better to create an additional OnlineContainer with "OnlineVariable.VariableChange"
'#######################################
'Private Sub zOLV_VariableBulkChange(pvVars As Variant, pvPvIDs As Variant, pvValues As Variant, pvStatesLo As Variant, pvStatesHi As Variant, pvTimes As Variant)
'
'Dim i As Integer
'
' Debug.Print "Changed Variables: " & UBound(pvVars)
' For i = 0 To UBound(pvVars)
' Debug.Print " - [" & pvPvIDs(i) & "] " & pvVars(i).Name & " = " & pvValues(i)
' Next i
' Debug.Print "----------------------------------------------------------------"
'End Sub
Private Sub Project_Inactive()
'relase objects
If Not zOLV Is Nothing Then
zOLV.Undefine
End If
thisProject.OnlineVariables.DeleteOnlineVariables ("myOLV")
Set zOLV = Nothing
End Sub
This is a migrated post! Originally posted on 10.02.2009 by user herberto. Please be aware that information can be outdated.