Samples 10.5.2 View active alarms in user defined ListView The following example shows how to create a user defined List View in Visual Basic for the TcEventLogger, that shows active events. Do following steps to create the sample: 1. Create a standard EXE project with a form. 2. Add MS Standard Controls 6 to the Control list. 3. Add the Beckhoff TcEventLogger Library to the references. 4. Add the List View ActiveX Control to the form. 5. Rename the List View to lvwAlarm 6. Copy following Code to the form:
Option Explicit Dim WithEvents objEventLogger As TcEventLog '------------------------------------------------------ ' this method is called when the form is loaded ' Private Sub Form_Load() Set objEventLogger = New TcEventLog Call initListView Call DisplayActiveAlarms End Sub '------------------------------------------------------ ' this method is called when a new alarm is issued ' Private Sub objEventLogger_OnNewEvent(ByVal evtObj As Object) ' cast to TcEvent interface Dim objEvent As TcEvent Set objEvent = evtObj ' get the key Dim newKey As String newKey = GetKeyFromIDs(objEvent.SrcId, objEvent.Id) 'get the Event Message Text Dim strMessage As String strMessage = objEvent.GetMsgString(1033) 'add the Message to the listview Dim objListItem As ListItem Set objListItem = lvwAlarm.ListItems.Add(, newKey, strMessage & objEvent.Date) End Sub '------------------------------------------------------ ' this method is called when a alarm is reset ' Private Sub objEventLogger_OnResetEvent(ByVal evtObj As Object) ' cast to TcEvent interface Dim objEvent As TcEvent Set objEvent = evtObj ' get the key Dim newKey As String newKey = GetKeyFromIDs(objEvent.SrcId, objEvent.Id) 'remove the event from the listview Call lvwAlarm.ListItems.Remove(newKey) End Sub '------------------------------------------------------ ' initalize the list view ' Sub initListView() lvwAlarm.View = lvwReport lvwAlarm.GridLines = True 'init the Header Dim objColHdr As ColumnHeaders Set objColHdr = lvwAlarm.ColumnHeaders Debug.Assert Not objColHdr Is Nothing Call objColHdr.Clear Call objColHdr.Add(1, "Message", "Message", 5000) End Sub '------------------------------------------------------ ' display all active alarms ' Private Sub DisplayActiveAlarms() TcEventLogger 197 Version:
1.1