Level A Walk-Through — Windows

See Also

This section describes how the Windows client application of the Island Hopper News sample Level A works, including both what you see as a user and what happens behind the scenes. If possible, run the application as you read through this section, and look at the source code, which you'll find in Program Files\IslandHopper\ScenarioA\classifieds.vbg. For complete information on all the different parts of Level A, see Level A Specification in this chapter.

First Impressions

When you start the Windows client, you see what appears to be a single form with the caption "Island Hopper News."

This is actually an MDI form, frmParentA, which calls a child, frmAccountingA, immediately. The child form contains the controls and background you see.

The main screen of the sample offers you the following three choices.

Notice how the labels change color when you move the pointer over them. This is done by detecting the mouse move and changing the color of the labels. Look at the code for frmAccountingA and locate the Form_MouseMove and lblOption_MouseMove methods.

Browsing Ads

Click Browse Ads to display the Browse Ads form, frmDisplayAdsA. This form consists of two parts: the list of ad categories on the left and the list of ads on the right. Click a category to see the ads in that category, and then click the title of an ad to see the text of the ad.

How It's Done

The list of categories is a standard ListBox control that is populated through a method called FillAdsByCategory. You can see this method if you look at the code for frmDisplayAdsA. The FillAdsByCategory method instantiates the db_CategoryA component to access the database, Classifieds.mdb, and return a list of all the categories in the Categories table.

The list of ads is displayed by a WebBrowser control. The WebBrowser control is available with Internet Explorer 4.0 and later, and with it you can display Web pages as part of a Visual Basic form. The WebBrowser control locates the Web server and displays an Active Server Pages file, AdsList.asp, which contains the ads that apply to the selected category. To see how this is done, look at the lstCategory_Click event code for frmDisplayAdsA.

Retrieving Ads

Click Ad Maintenance to display the Ad Maintenance form, frmAdA. You can use this form to retrieve an ad from the database. You must supply both an e-mail address and a phone number to retrieve ads. If you have not placed any new ads yourself yet, you can use someone@microsoft.com for the e-mail address and 555-5555 for the phone number to retrieve some ads. You can click Place Ads to place an ad, but you must supply an e-mail address and phone number first.

How It's Done

The Ad Maintenance form instantiates the bus_AdA component when it loads. When you fill in an e-mail address or phone number and click Retrieve, the corresponding bus_AdA method (ListByMail or ListByPhoneNumber) is called. Both of these methods instantiate the db_AdA component to perform the actual retrieval.

The retrieved ads are displayed in an MSFlexGrid control. Double-clicking on an ad displays the Ad Details form, frmAdDetailA. Clicking Place Ads also displays the Ad Details form.

Placing and Editing Ads

You can update, delete, or place new ads with the Ad Details form, frmAdDetailA. These three modes are controlled by a set of option buttons in the upper left corner. The mode that is enabled when the form is displayed depends on how you got to the form. If you clicked Place Ads, the Ad Details form is displayed with the Place New Ad option selected. If you double-clicked an ad on the Ad Maintenance form, the Ad Details form is displayed with the Update option selected and the ad's information displayed. You can delete an ad by clicking the Delete option button.

How It's Done

When the Ad Details form is loaded, it instantiates the bus_AdA component, calls the FillCategory and FillDuration methods to populate the Category and Duration combo boxes, and clears all the text fields in preparation for input. Then the form is activated. The activation code determines which option button should be enabled.

The FillDuration method uses the ComboBox control's AddItem method to populate the Duration combo box. The FillCategory method instantiates the db_CategoryA component to access the database and retrieve the categories, and then uses the AddItem method to populate the combo box.

When the Ad Details form is activated, it calls the RetrieveAdByID method to retrieve the ad from the database. RetrieveAdByID uses the GetByID method of bus_AdA to retrieve the ad information and populate the fields.