home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


CalendarModel The CalendarModel class defined in module CalModel.CLS is AppointmentBook’s model class. It is responsible for loading, saving, and providing access to the data, in addition to the standard model duties of registering views and providing event notification.

CalVC The CalVC view/controller class defined in CalVC.CLS manages the month area. As a view, the class redraws the month area whenever it receives notification of a CAL_TopDateChanged, CAL_Resized, CAL_AppointmentChanged, or CAL_DailyApptDeleted event.

The class also responds to the CAL_SelectedDateChanged event that indicates that a new date has been selected. If the event is combined with one of the previous events, the other event causes the calendar to be completely redrawn so no further action is needed. Otherwise, the Notify subroutine highlights the newly selected date.

As a controller, CalVC interacts with the model in three ways. When the program resizes the month area, the Resize event for the area’s picture box invokes the CalVC’s Resized subroutine. This routine, in turn, calls the model’s Resized subroutine. That routine notifies interested views that the area has resized. Because CalVC is an interested view, it will be notified so it can redraw itself.

CalVC’s second controller function handles key presses. When AppointmentBook receives a KeyUp event, it invokes CalVC’s KeyUp subroutine. That routine decides whether the key was an arrow key and how it should change the selected date. It then uses the model’s SelectedDate property procedure to select the new date. Note that CalVC decides which date should be selected and then tells the model. This keeps the model simple.

Finally, CalVC responds to mouse events. The MonthPict picture box contains the month area. When MonthPict receives a MouseUp event, it invokes CalVC’s MouseUp subroutine. This routine uses the coordinates where the user clicked to determine which date should be selected. It then uses the model’s SelectedDate property procedure to select the new date. Once again, CalVC decides which date should be selected and then tells the model. It is the model’s job to make changes and notify the appropriate views, not to decide what changes to make.

ScrollVC The ScrollVC view/controller class defined in ScrollVC.CLS manages the month area’s scroll bar. As a view, the class resets the scroll bar’s Min, Max, LargeChange, and Value properties whenever it is notified of a CAL_YearsChanged or CAL_Resized event. When it receives a CAL_SelectedDateChanged event, it resets only the scroll bar’s value.

As a controller ScrollVC has two purposes. When the scroll bar’s value changes, ScrollVC’s Scroll subroutine invokes the model’s SelectedWeek subroutine indicating the week that should contain the selected date. SelectedWeek determines the correct date and selects it. In this case the model does a bit more work than it does when the CalVC tells it exactly what date to select. This is convenient because the model needs to check the new date to ensure that it lies within the bounds of the available data. The model can adjust the selected date if necessary to keep it in bounds.

In its second controller function, ScrollVC uses the model’s TemporaryWeek property procedure. When the user drags the month area’s slider, ScrollVC sets TemporaryWeek to indicate the week that would be selected if the user releases the slider. TemporaryWeek is very similar to SelectedWeek except it sets the model’s temporary date instead of its selected date. This allows the DateLabelV view described in the next section to display the temporarily selected date above the daily appointment area.

DateLabelV The DateLabelV view class defined in LabelV.CLS manages the date label above the daily appointment area. This view is quite simple. When it is notified of a CAL_SelectedDateChanged event, it displays the selected date in text form. When it is notified of a CAL_TemporaryDateChanged event, it displays the temporary date.

DailyV The DailyV view class defined in DailyV.CLS is also fairly simple. It manages the daily appointment display. When it is notified of a CAL_SelectedDateChanged or CAL_AppointmentChanged event, it redisplays the appointments for the selected date.

Even the way in which DailyV displays the appointments is simple. First, it uses the model’s GetDailyAppt subroutine to get a reference to the DailyAppt object that represents the appointments for the selected date. It then invokes the DailyAppt object’s ShowAppts subroutine to make the object display itself. The DailyAppt object’s ShowAppts subroutine does the hard part.

Scrolling Daily Appointments AppointmentBook draws the selected date’s complete schedule in the daily appointment area. A scroll bar allows the user to scroll through the schedule. This operation is so simple that it really does not need a special class as does scrolling the month area. The scroll bar’s Change event adjusts the top of the scrolling area much as the scroll bar does in ExpenseReporter.

Private Sub DailyVScroll_Change()
    DailyPict.Top = -DailyVScroll.Value
End Sub

AlarmV The AlarmV view class defined in AlarmV.CLS is slightly different from the other views in AppointmentBook. The other views react to changes in the data and present updated displays of the data. When the selected date changes, for example, the month area highlights the newly selected date.

The AlarmV view, on the other hand, does not immediately display any data. When it is notified of a change in the appointment data, this view schedules an action to occur later.

AlarmV is notified when an appointment is modified, when an appointment is deleted, and when the user is warned about an appointment. When AlarmV receives notification, it examines all of the appointments to find the one the user will need to be notified about next. It then sets an alarm to wait until the time at which it needs to notify the user. The method AppointmentBook uses to set alarms is described in the later section, “Setting Alarms.”


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.