Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] - نسخه متنی

Alison Balter

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



Adding Your Own Events


Just as you can add custom properties and methods to the classes that you build, you can also add custom events. You will often use custom events to return information back to the application code that uses them. For example, if an error occurs in the Class module, it is prudent to raise an event to the user of the class, notifying it that the error occurred. Error handling is one of the

many uses of a custom event. To declare a custom event, place a Public Event statement in the General Declarations section of the Class module:

Public Event Speaking(strNameSaid As String)

This statement declares a Speaking event that passes a string up to its caller. After you have declared an event, you must then raise it in the appropriate place in the class code. You raise an event with the RaiseEvent command. Realize that custom events mean nothing to Access or to the operating system. In other words, they are not triggered by something that the operating system responds to. Instead, you generate them with the code that you write, in the places in your application where you deem appropriate. Although you can declare an event only once, you can raise it as many times as you like. The following is an example of raising the Speaking event from the Speak method of the class:

Public Function Speak()
Dim strNameSaid As String
Speak = mstrFirstName & " " & mstrLastName
strNameSaid = mstrLastName & ", " & mstrFirstName
RaiseEvent Speaking(strNameSaid)
End Function

In this example, the Speak method raises the Speaking event. It passes the concatenation of the last name and first name spoken back to the caller.

After you have raised an event, you need to respond to it in some other part of your application. You can only respond to events in Class modules (form, report, or standalone). You must first create an object variable that is responsible for reporting the events of the class to your application:

Private WithEvents mobjPerson As Person2

You can then select the class from the Objects drop-down, and the event from the Procedures drop-down. The code that follows responds to the Speaking event, displaying what was said in a message box:

Private Sub mobjPerson_Speaking(strNameSaid As String)
MsgBox strNameSaid
End Sub

/ 544