Professional Excel Development [Electronic resources] : The Definitive Guide to Developing Applications Using Microsoft® Excel and VBA® نسخه متنی

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

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

Professional Excel Development [Electronic resources] : The Definitive Guide to Developing Applications Using Microsoft® Excel and VBA® - نسخه متنی

Stephen Bullen, Rob Bovey, John Green

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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











A Plug-in Architecture


You saw in Chapter 10 Userform Design and Best Practices how it was possible to create a user interface consisting of modeless userforms, in which the interaction with the user occurs within userforms (as opposed to worksheets), yet with the command bars still usable. To allow the forms to respond to menu bar clicks (such as saving, moving to another form or closing the application), we had to ensure that all our forms had the same basic set of routines, that could be called by our common menu handler. Those routines were called BeforeNavigate, BeforeSave, AfterSave and AppExit. We had in fact created our own implicit interface, without knowing it. By making that interface explicit, we can improve robustness and reliability and simplify the development of the application. We'll call this interface IPlugInForm and define it as shown in Listing 11-19, where we've also added a Show method, to be able to show the form through this interface.

Listing 11-19. The IPlugInForm Interface Class



'Name: IPlugInForm
'Description: Interface to be implemented by each form
'Author: Stephen Bullen
'The form's name
Public Property Get Name() As String
End Property
'Show the form
Public Sub Show(Optional ByVal Style As _
FormShowConstants = vbModal)
End Sub
'The user clicked a menu item to navigate to a different form
'Save any changes on the form and unload
Public Sub BeforeNavigate(ByRef bCancel As Boolean)
End Sub
'The user clicked the Save button
'Save any changes on the form and unload
Public Sub BeforeSave(ByVal bSaveAs As Boolean, _
ByRef bCancel As Boolean)
End Sub
'After the save completed
'Update the form with any new information
Public Sub AfterSave(ByVal bSaveAs As Boolean)
End Sub
'The user clicked the Close button to exit the application
'Tidy up and unload the form
Public Sub AppExit()
End Sub

If all of our forms implement this interface, the central control routine shown in Listing 10-26 in Chapter 10 Userform Design and Best Practices can declare the gfrmActiveForm variable As IPlugInForm instead of As Object and call the same methods as before. Using the interface enables us to be explicit about what the code is doing, prevents typing errors, ensures none of our common routines are "accidentally" deleted from the forms and helps enforce a common structure throughout the application.


/ 225