Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Table of Contents

Chapter 3: User Interface Design: Visual Basic Controls and Events
Last change: February 13 2016 18:47:26.

The Visual Interface

Again, the first step in developing a VB project is to design the visual interface. In this step, you consider what VB control should be used for each of the required data elements.

After you understand the requirements for your project, carefully analyze the nature of the data field so that you can use the best control for its purpose. The most suitable control for the data field can make both the data entry operation and your code efficient and effective.

Date of Order

A date field has a specific format. The masked text box appears to be the best choice. Name this control mskDate. In addition, set its Mask property to “00/00/0000” (short date) at design time.

Distributor Number

As the project description states, there are only two distributors. The data field under consideration has a limited number of choices. Controls that may be appropriate would seem to be either the check box or radio button. Notice that only one distributor can place an order; therefore, the control that comes to mind immediately is the radio button. However, in this case, the radio button is probably not the best choice because the number of distributors can change over time, as the project description implies. If you use the radio buttons, each time the company adds or deletes a distributor, the visual interface will need to be revised. Obviously, this is not an ideal solution.
As discussed previously in this chapter, the other possible VB controls for known choices are the list box or combo box. In the real-world application, the names of the distributors can be added to these controls from a file or database maintained by the user. The use of either the list box or combo box can eliminate the need to revise the program as a result of any change in distributors.
Should you use the list box or the combo box? If you go through the list of criteria for determining the appropriate control between the two, you should find the two controls tie almost all the way. This suggests that the appearance of the control is the determining factor. You would like for the control to appear as a box for a single line input, so your best choice for this purpose should be the combo box. Name it cboDistributor.

Model Number

The factors to consider for the control for the model number are similar to those for the distributor number. The dynamic nature of known items (adding and dropping models) and the appearance consideration suggest that you should also use the combo box. Name this control cboModel.
Note that the model number should be selected from the list of existing models, not keyed in by the user. This means that the DropDownStyle property of cboModel should be set to DropDownList, not the default setting, DropDown. The model numbers should be added to the combo box using the Items.Add method when the program starts, and not set at design time by editing the List property. In real applications, these models should be read from a file or database maintained by the user. Files and databases are discussed in later chapters.
Indeed, all these same considerations also apply to the distributor number. Therefore, the DropDownStyle property of cboDistributor should also be set to DropDownList.

Quantity Ordered

The main consideration here is that keys entered into this data field should be numeric. There is a range of values (500 to 2,500) that is considered typical. It appears that the number entered should not exceed four digits. Either a text box or a masked text box should be suitable. You will use the text box for this purpose and name it txtQuantity. In addition, you should also set theMaxLength property of this control to 4. This property gives the maximum number of characters the user can enter in the box. Setting the maximum length will ensure that the user cannot accidentally enter a number that exceeds the reality.

Use the MaxLength property to limit the number of characters the user can enter into a text box when the number can be determined at design time. This can help eliminate unexpected extra keys into the box, which can cause problems for your program.

Special Instructions

Finally, you need to determine whether the order is a rush order. Because this is a yes-or-no question, it appears that the check box will serve as a good visual interface. Name it chkRush. In addition, when it is a rush order, you should also record the type of delivery: U.P.S. or special carrier. Because the user will be choosing between the two types of carriers (mutually exclusive choices), radio buttons appear to be the most appropriate. Name them rdbUPS and rdbSpecialCarrier.
As a side note, you may argue that the combo box can be a better choice than the radio buttons in this case, based on the same considerations given to distributor numbers and model numbers. Yes, you are right. The choice here is based more on the interest to demonstrate how radio buttons can be used.

Buttons and the Form

In addition to the data fields already considered, you should also provide a means for the user to save data and end the program. You can do this by adding two buttons to the form. One will be named btnSave with the text Save; another, named btnQuit with the text Quit.
You should also set the proper Text and Name properties for the form. You will name the form frmSalesOrder and set its text to Environ-Pure Sales Order Entry Form.

Grouping and Layout

After having decided what VB controls to use for all required data fields, you can consider how these controls should be arranged. The VB controls for special delivery instructions are logically related; therefore, they should be grouped together, perhaps within a group box. The other fields all pertain to the order itself; they can be grouped in another group box. All these fields should have proper labels to indicate the nature of the field. The buttons are usually placed at the bottom or the right side of the form. In this form, the layout should look neat when the two buttons are placed at the bottom.

When you have to place several controls on a form, be sure to take advantage of the group box. Group boxes can help your form layout appear neat and logical.
With all these considerations, you can now draw two group boxes and all labels onto a form. You will also set the Text properties for all controls properly. You will then add the other controls discussed above and set the properties of each control properly. The following table provides a summary of the settings for these properties:
Field/Button Type of Control Property Setting
Date of Order Masked text box Name mskDate
Mask 00/00/0000
Distributor No. Combo box Name cboDistributor
    DropDownStyle DropDownList
Model No. Combo box Name cboModel
DropDownStyle DropDownList
Quantity Ordered Text box Name txtQuantity
Text (blank)
MaxLength 4
Rush Order? Check box Name chkRushOrder
Text Rush Order?
U.P.S. Radio button Name rdbUPS
Text U.P.S.
Special Carrier Radio button Name rdbSpecialCarrier
Text Special Carrier
Save button Button Name btnSave
Text Save
Quit button Button Name btnQuit
Text Quit
Form Form Name frmSalesOrder
Text Environ-Pure Sales Order Entry Form

The resulting form layout appears as Figure 3.18.

 Figure 3-18
The visual interface for Environ-Pure

Pay particular attention to the appearance of the masked text box. The string __/__/____ should appear in the date field if the Mask property of the masked text box is set properly.

Last change: February 13 2016 18:47:27.