Showing results 1 to 3 of 3

Thread: Create AlarmClasses / AlarmGroups / AlarmAreas via VBA

  1. #1
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    881

    Default Create AlarmClasses / AlarmGroups / AlarmAreas via VBA

    With zenOn versions >= 6.22 it is possible to create AlarmClasses / AlarmGroups / AlarmAreas via VBA:

    Private Sub CreateAlarmClassGroupArea()
    Dim nClassCurrentAmount As Integer
    Dim nGroupCurrentAmount As Integer
    Dim nAreaCurrentAmount As Integer
    Dim nLastColor As Double
    Dim strLastClassName As String
    Dim strLastGroupName As String
    Dim strLastAreaName As String
    
    'Dynamicaly create a new Class
    nClassCurrentAmount = MyWorkspace.ActiveDocument.DynProperties("AlarmClasses")
    If (nClassCurrentAmount > 0) Then
        nLastColor = MyWorkspace.ActiveDocument.DynProperties("AlarmClasses[" & Trim(Str(nClassCurrentAmount - 1)) & "].Color")
    End If
    MyWorkspace.ActiveDocument.CreateDynProperty ("AlarmClasses")
    strLastClassName = "ClassName" & Trim(Str(nClassCurrentAmount + 1))
    MyWorkspace.ActiveDocument.DynProperties("AlarmClasses[" & Trim(Str(nClassCurrentAmount)) & "].Name") = strLastClassName
    MyWorkspace.ActiveDocument.DynProperties("AlarmClasses[" & Trim(Str(nClassCurrentAmount)) & "].Description") = "ClassText" & Trim(Str(nClassCurrentAmount + 1))
    MyWorkspace.ActiveDocument.DynProperties("AlarmClasses[" & Trim(Str(nClassCurrentAmount)) & "].Color") = nLastColor + 1000
    
    'Dynamicaly Create a new Group
    nGroupCurrentAmount = MyWorkspace.ActiveDocument.DynProperties("AlarmGroups")
    If (nGroupCurrentAmount > 0) Then
        nLastColor = MyWorkspace.ActiveDocument.DynProperties("AlarmGroups[" & Trim(Str(nGroupCurrentAmount - 1)) & "].Color")
    End If
    MyWorkspace.ActiveDocument.CreateDynProperty ("AlarmGroups")
    strLastGroupName = "GroupName" & Trim(Str(nGroupCurrentAmount + 1))
    MyWorkspace.ActiveDocument.DynProperties("AlarmGroups[" & Trim(Str(nGroupCurrentAmount)) & "].Name") = strLastGroupName
    MyWorkspace.ActiveDocument.DynProperties("AlarmGroups[" & Trim(Str(nGroupCurrentAmount)) & "].Description") = "GroupText" & Trim(Str(nGroupCurrentAmount + 1))
    MyWorkspace.ActiveDocument.DynProperties("AlarmGroups[" & Trim(Str(nGroupCurrentAmount)) & "].Color") = nLastColor + 1000
    
    'Dynamicaly Create a new Area
    nAreaCurrentAmount = MyWorkspace.ActiveDocument.DynProperties("AlarmAreas")
    MyWorkspace.ActiveDocument.CreateDynProperty ("AlarmAreas")
    MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCurrentAmount)) & "].Name") = "AreaName" & Trim(Str(nAreaCurrentAmount + 1))
    MyWorkspace.ActiveDocument.CreateDynProperty ("AlarmAreas[" & Trim(Str(nAreaCurrentAmount)) & "].Items")
    MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCurrentAmount)) & "].Items[0].StatusVar") = 4
    MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCurrentAmount)) & "].Items[0].AlarmVar") = 5
    MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCurrentAmount)) & "].Items[0].QuitVar") = 6
    MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCurrentAmount)) & "].Items[0].ClassName") = strLastClassName
    End Sub

    Below you can find how to read AlarmClasses / AlarmGroups / AlarmAreas:

    Private Sub GetAlarmClassGroupArea()
    
    Dim nCounter As Integer
    Dim nGrpCounter As Integer
    Dim nGrpAmount As Integer
    Dim nClsCounter As Integer
    Dim nClsAmount As Integer
    Dim nAreaCounter As Integer
    Dim nAreaAmount As Integer
    Dim nAreaItemAmount As Integer
    Dim nAreaItemCounter As Integer
    nClsAmount = MyWorkspace.ActiveDocument.DynProperties("AlarmClasses")
    nAreaAmount = MyWorkspace.ActiveDocument.DynProperties("AlarmAreas")
    nGrpAmount = MyWorkspace.ActiveDocument.DynProperties("AlarmGroups")
    
    If (nGrpAmount > 0) Then
        For nGrpCounter = 0 To nGrpAmount - 1
            Debug.Print "GrpName:" & MyWorkspace.ActiveDocument.DynProperties("AlarmGroups[" & Trim(Str(nGrpCounter)) & ".Name")
            Debug.Print "GrpText:" & MyWorkspace.ActiveDocument.DynProperties("AlarmGroups[" & Trim(Str(nGrpCounter)) & ".Description")
            Debug.Print "Color:" & MyWorkspace.ActiveDocument.DynProperties("AlarmGroups[" & Trim(Str(nGrpCounter)) & ".Color")
            Debug.Print "Number:" & MyWorkspace.ActiveDocument.DynProperties("AlarmGroups[" & Trim(Str(nGrpCounter)) & ".Id")
        Next
    End If
    
    If (nClsAmount > 0) Then
        For nClsCounter = 0 To nClsAmount - 1
            Debug.Print "ClsName:" & MyWorkspace.ActiveDocument.DynProperties("AlarmClasses[" & Trim(Str(nClsCounter)) & ".Name")
            Debug.Print "ClsText:" & MyWorkspace.ActiveDocument.DynProperties("AlarmClasses[" & Trim(Str(nClsCounter)) & ".Description")
            Debug.Print "Color:" & MyWorkspace.ActiveDocument.DynProperties("AlarmClasses[" & Trim(Str(nClsCounter)) & ".Color")
            Debug.Print "Number:" & MyWorkspace.ActiveDocument.DynProperties("AlarmClasses[" & Trim(Str(nClsCounter)) & ".Id")
        Next
    End If
    
    If (nAreaAmount > 0) Then
        For nAreaCounter = 0 To nAreaAmount - 1
            Debug.Print MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCounter)) & ".Name")
            nAreaItemAmount = MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCounter)) & ".Items")
            If (nAreaItemAmount > 0) Then
                For nAreaItemCounter = 0 To nAreaItemAmount - 1
                    Debug.Print MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCounter)) & ".Items[" & Trim(Str(nAreaItemCounter)) & "].ClassName")
                    Debug.Print MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCounter)) & ".Items[" & Trim(Str(nAreaItemCounter)) & "].StatusVar")
                    Debug.Print MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCounter)) & ".Items[" & Trim(Str(nAreaItemCounter)) & "].AlarmVar")
                    Debug.Print MyWorkspace.ActiveDocument.DynProperties("AlarmAreas[" & Trim(Str(nAreaCounter)) & ".Items[" & Trim(Str(nAreaItemCounter)) & "].QuitVar")
                Next
            End If
        Next
    End If
    End Sub

  2. #2
    Join Date
    15.11.2011
    Posts
    7

    Default AW: Create AlarmClasses / AlarmGroups / AlarmAreas via VBA

    I want to access to the alarmclass by name in the runtime - is this possible?

  3. #3
    josefm Gast

    Default Re: AW: Create AlarmClasses / AlarmGroups / AlarmAreas via VBA

    Hi lew,

    please find this information in the help topic "Manual -> Programming interfaces -> Object model -> AlarmItem -> AlarmClass". To access alarms by name is not possible. You can only read the alarm class of an alarm during the runtime.

    What is your need to access the alarm class by name?


    Best regards

Similar Threads

  1. Create a function for a trend picture
    By robertf in forum VBA
    Replies: 8
    Last Post: 4th October 2018, 14:33
  2. Create an Element
    By robertf in forum VBA
    Replies: 7
    Last Post: 11th June 2014, 07:44
  3. How to create a new MACRO?
    By matholton in forum VBA
    Replies: 2
    Last Post: 24th September 2008, 12:14

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •