COPA-DATA  



VBA All about VBA, automatic engineering, the zenon project wizard, ...

Reply
  #1  
Old 10th February 2009, 12:54
herberto's Avatar
herberto herberto is offline
Moderator
 
Join Date: 30.05.2007
Location: Salzburg
Posts: 740
Idee 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



Visualbasic 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

Last edited by herberto : 10th February 2009 at 12:56. Reason: removed debug.print message...
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamische Onlinevariablen im Container bzoller VBA 10 25th September 2008 14:45
Online Browsing of variables at the driver under Windows Vista is not working. wolfgangm Data Acquisition 0 19th September 2007 11:06
Redundancy, Standby reads values although the server is online wolfgangm Network, Messaging 0 21st August 2007 09:35


All times are GMT +1. The time now is 19:57.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.