Showing results 1 to 9 of 9

Thread: Get alarm messages in VBA

  1. #1

    Default Get alarm messages in VBA

    Hi,

    I need to write macro in my project, that will get alarm messages from variables in alarm and write it to string variable.
    I have created the macro, but it doesn`t work. Could you please help me, may be some advises or recomendations?

    Here is my code:

    Public Sub GetValues()
    Dim zVariables As Variables
    Dim zVariable As Variable
    Dim obAlarm As Alarm
    Dim obAlarmItem As AlarmItems
    Dim infoTagName As String
    
    Set zVariables = thisProject.Variables
    Set zVariable = zVariables.Item("var_alarm_string")
    
    Set obAlarm = thisProject.Alarm
    Set obAlarmItem = obAlarm.AlarmItems
    
    Set infoText = obAlarm.Item.Tagname
    Set zVariable.Value = infoText
    
    End Sub


    Regards, Nataliia

  2. #2
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Re: Get alarm messages in VBA

    hi,

    for displaying the limit text of violated limit from a variable you simply link the desired variable to the dynamic text element.... no need doing this via the programming interface...

    regards,
    herbert


  3. #3

    Default Re: Get alarm messages in VBA

    Quote Originally Posted by herberto View Post
    hi,

    for displaying the limit text of violated limit from a variable you simply link the desired variable to the dynamic text element.... no need doing this via the programming interface...

    regards,
    herbert
    I think, I have not good explained my task.

    I need to get alarm texts from any variables.
    So if I will use the dynamic text element - I connect it with only one variable.
    However I need only one string with changing value (= existing alarm tagname) for all variables that can be in alarm in my project.

  4. #4
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Re: Get alarm messages in VBA

    I need to get alarm texts from any variables.
    So if I will use the dynamic text element - I connect it with only one variable.
    However I need only one string with changing value (= existing alarm tagname) for all variables that can be in alarm in my project.
    How do you make the selection for which variable you want to see the alarm text?
    Furthermore why do you need this alarm information on 1 single string variable?

    A more precise desription would be very helpful^^

    Regards,
    Herbert


  5. #5

    Default Re: Get alarm messages in VBA

    Quote Originally Posted by herberto View Post
    How do you make the selection for which variable you want to see the alarm text?
    Furthermore why do you need this alarm information on 1 single string variable?

    A more precise desription would be very helpful^^
    I would like to show in one dynamic text element the string with active alarm and also use it in my another macro.

    In manual I saw some examples: Manual -> Programming interfaces -> VBA -> Examples -> Access to alarms

    But I don`t sure, that part of code, that determines access to alarm variable, really works:

    Dim i As Integer 
    Dim obAlarmItems As AlarmItems 
    Dim obAlarm As Alarm 
    
    Set obAlarm = thisProject.Alarm 
    Set obAlarmItems = obAlarm.AlarmItems (*) 
    
    If obAlarmItems.Count = 0 Then 
    MsgBox (# Alarms = 0 ) 
    Exit Sub 
    End If 
    
    For i = 0 To obAlarmItems.Count - 1 
    cmbAlarmItems.AddItem obAlarmItems.Item ( i ). Name 
    Next i


    Especially, this:
    Set obAlarmItems = obAlarm.AlarmItems (*)

  6. #6
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Re: Get alarm messages in VBA

    I'm sure there exists also way without using VBA for this.... nevertheless

    There is an example on this in the help documentation at:
    Manual -> Programming interfaces -> Object model -> AlarmItem

    I just Copy&Paste the example from there into the project and it was working well.

    br,
    herbert


  7. #7

    Default Re: Get alarm messages in VBA

    Herbert,
    thank you. I will try it.

    Regards, Nataliia

  8. #8

    Default Re: Get alarm messages in VBA

    I have modified Sub for my goal. Here is a result, if anybody will need it:

    Public Sub GetAlarmItems()
        Dim zAML As Alarm
        Dim zAML_Items As AlarmItems
        Dim zAML_Item As AlarmItem
        Dim i As Integer
        Dim info As String
        Dim zVariables As Variables
        Dim zVariable As Variable
        
        'Write alarm message into string 
        Set zVariables = thisProject.Variables
        Set zVariable = zVariables.Item("var_alarm_message")
    
        'Get alarm variables
        Set zAML = thisProject.Alarm
        Set zAML_Items = zAML.AlarmItems("*")
        
        'Get only last one
        i = zAML_Items.count - 1
        Set zAML_Item = zAML_Items.Item(i)
    
        info = zAML_Item.Text
        zVariable.Value = info
        zAML_Items.count = 0
    
    End Sub

    Regards,
    Nataliia

  9. #9
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    879

    Default Re: Get alarm messages in VBA

    FYI: it is also possible to pre-filter the list

    instead of
    Set zAML_Items = zAML.AlarmItems("*")
    you can put there the name of the screen switch function to the AML
    i.e.
    Set zAML_Items = zAML.AlarmItems("fct_AML_screen")

    All the settings (filter options) with the screen switch function to the AML will be applied to the filter result in VBA.

    regards,
    herbert


Similar Threads

  1. System messages
    By tihomir in forum zenon Supervisor
    Replies: 5
    Last Post: 28th November 2013, 11:28
  2. Replies: 2
    Last Post: 21st January 2013, 16:14
  3. CEL - Internal System Messages
    By danillu in forum zenon Supervisor
    Replies: 3
    Last Post: 12th March 2012, 00:15
  4. GOOSE messages in STRATON
    By mansoorhussain in forum straton / zenon Logic
    Replies: 3
    Last Post: 14th January 2011, 00:37
  5. Replies: 9
    Last Post: 21st May 2008, 15:23

Posting Rules

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