You are here: Core Reference > Coding > Scripting > Example 2: Extracting Alarm Information and User Entered Content

Example 2: Extracting Alarm Information and User Entered Content

In this example, the script is used to add a menu option to the Alarm Banner, that when selected, extracts alarm information from the Alarm Banner in ViewX and displays it on a Form. The Form also contains a field which requires the user to enter information. When the user has entered the requested information and selected the OK button, a confirmation window is displayed. If the user selects the Yes button on the confirmation window, the extracted Alarm Banner information and the details entered by the user are displayed in a message box.

Example:

On a real system, instead of displaying the alarm information and user input on a message box, it is more likely that you would create a script to send the extracted information to another application. For example, you could send the alarm information and user-defined input to a work management program. The method and scripting required to send the information to third-party programs varies for each application—for more information, please refer to the documentation supplied with your third-party application.

  • Public Sub BuildAlarmMenu
  • If AlarmBanner.SelectedAlarms.Count > 0 Then
    • AlarmBanner.AddMenuItem "Acknowledge Related Alarms", "AcknowledgeRelated"
  • End If
  • End Sub
  •  
  • Public Sub AcknowledgeRelated
    • If AlarmBanner.SelectedAlarms.Count > 0 Then
      • Form.Init "Process Alarms"
      • Form.AddStaticText 1, 1, "Alarms Selected:"
      • Count = 0
      • For Each objAlarm In AlarmBanner.SelectedAlarms
      • Form.AddStaticText 1, 3 + Count, objAlarm.Source & ", " & objAlarm.Message
      • Count=Count + 1
    • Next
    • Form.AddStaticText 1, 4 + Count, "Further Information:"
    • Set frmEdit = Form.AddEditBox(25, 4 + Count, 50, 1)
    • Set frmOk = Form.AddPushButton(45, 7 + Count, "OK")
    • Set frmCancel = Form.AddPushButton(60, 7 + Count, "Cancel")
    • frmOk.Default = True
    • Form.Show
    •  
    • If Form.Selection = "OK" Then
      • lResult = MsgBox("Process the alarms with information '" & frmEdit & "'?", vbYesNo + vbDefaultButton2 + vbQuestion, "Confirm Action")
      • If lResult = vbYes Then
      • Form.Init "Result"
      • Form.AddStaticText 1, 1, "Alarms Selected:"
      • Count = 0
      • For Each objAlarm In AlarmBanner.SelectedAlarms
      • Form.AddStaticText 1, 3 + Count, objAlarm.Source & ", " & objAlarm.Message
      • Count = Count + 1
      • Next
      • Form.AddStaticText 25, 4 + Count, frmEdit
      • Set frmOk = Form.AddPushButton(45, 7 + Count, "OK")
      • Set frmCancel = Form.AddPushButton(60, 7 + Count, "Cancel")
      • frmOk.Default = True
      • Form.Show
      • End If
    • End If
  • End If
  • End Sub

 

This script adds an Acknowledge Related Alarms option to the Alarm Banner in ViewX.

When a user selects the Acknowledge Related Alarms option, a Form is displayed. The Form contains alarm information extracted from the Alarm Banner as well as a Further Information field.

The user enters additional details about the alarm in the Further Information field.

The user then selects the OK button and a confirmation window is displayed. The confirmation window contains the information entered by the user.

The user selects the Yes button and the extracted alarm information and the user-defined information are displayed in a message box.


ClearSCADA 2015 R2