tutorial

Page 168

'Declare a class which operates on the Employee collection database 'This class is used to find some summarised operation on the Employee 'collction database, which means finding the relavent employee ‘information, 'getting the total no. of employees in the collection and ‘others - Its just 'an example to explain how event works Public Class EmployeeCollection 'Declare an event which will be raised after finding the data 'Keyword ‘Event’ is used the declare the events Public Event FindResult(ByVal blnFound As Boolean) 'This method is to find the data from employee colletion database and 'raise the findresult event to return the result Public Sub FindData(ByVal Name As String) 'find the Employee with name and return the result as boolean, if 'the data is found then raise FindResult with True else with 'False Dim found As Boolean found = FineEmployee(Name) If found Then 'Raise the event with parameter RaiseEvent FindResult(True) Else 'Raise the event with parameter RaiseEvent FindResult(False) End If End Sub End Class

Usage:- In order to access the events of the objects, the object should be declared with withevents clause. This is shown in the following example with form load event. 'Declare the object with WithEvents clause to create an instance Dim WithEvents objEmpColl As EmployeeCollection = New EmployeeCollection() Public Sub load() 'Find the Employee with name Rama in the Employee collection objEmpColl.FindData("Rama") End Sub 'The following event will be raised after the search operation Private Sub objObject_FindResult(ByValue blnFound as Boolean) Handles objObject.FindResult If blnFound Then MsgBox("The given Employee is Found in the collection") Else MsgBox("The given Employee is not Found") End If End Sub

6.12 Structures


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.