![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Code in the procedure can set KeepFocus to True to cause the control to keep the focus after the event procedure executes. Leaving KeepFocus at the default value of False permits the focus to move away from the control. Heres an example Validate procedure that ensures that the data entered in the Text Box is a number: Private Sub Text1_Validate(KeepFocus As Boolean) If Not IsNumeric(Text1.Text) Then KeepFocus = True MsgBox You must enter a number here. End If End Sub What sort of things do you look for when validating data? It depends on the specific situation, of course, but several general criteria are often used:
The Basic language provides a full range of tools for validating data. Use of the Variant data type in data-validation routines is recommended. The automatic awareness of data type that Variant variables provide can eliminate some tedious coding, particularly when converting strings to numbers and numbers to strings. Functions such as IsNumeric and IsDate make certain types of validation trivial, while Visual Basics various string functions, such as Len and Instr, can be used to validate string data. Fundamental Program StructureBefore starting on a project of this complexity, you should always consider the various options that Visual Basic provides for the overall program structure and appearance. You know that the program requires several forms to display the database data in various ways and to permit entry and editing of data (why forms is in quotes will become clear). The user also needs a way to move between forms, selecting the task to be performed. First, look at the available options for displaying program elements:
Several options are also available for user control of the program. Of course, you can use these different control methods in combination with each other, but for the sake of simplicity, your demonstration project is limited to only one method. In a real, commercial application, youll probably want to use twofor example, a Toolbar plus menus. Here are the main ways that you can design a program to accept commands from the user:
For the purposes of the demonstration program, I decided to use an MDI interface with a Toolbar. Some other choices might have worked equally well, but this approach gives you the opportunity to learn how to implement an MDI interface and a Toolbartwo important Visual Basic tools. Preliminary Form DesignRather than trying to tackle the entire project at once, you start by designing and coding the simpler forms, and creating the MDI interface. For both the Customers table and the Wines table, you need a form that permits entering new records, editing existing records, and deleting existing records. These forms should be fairly straightforward, requiring a Text Box and identifying Label for each field, and a group of Command Buttons for the various actions. Youll also want a way to list all the records in the table on a single form, with the option of sorting the list based on different fields. In this situation, the DataGrid custom control comes in handy. But first you need the parent MDI form and its Toolbar. Creating The MDI Form And ToolbarCreating the MDI form first is not necessarybut it isnt a bad idea, either. Start a new standard EXE project and select Add MDI Form from the Project menu. Change the forms Caption property to Grapevine Wine Distributors. You can leave the forms Name property at the default value of MDIForm1, but when you save it, use the name GRAPEVINE.FRM (Use GRAPEVINE as the project name, too). Click-and-drag the Toolbar icon in the Toolbox to place a Toolbar on the form. Remember, if the Toolbar icon is not displayed in the Toolbox, you must use the Project, Components command to load it. The Toolbar is part of the set referred to as the Windows Common Controls. When you select this item in the Components dialog box, several controls, including the Toolbar, will be added to the Visual Basic toolbox. Working With The Toolbar ControlThe Toolbar starts out empty, with no buttons. You have the option of using text or images on the Toolbar buttons. For images, bind the Toolbar to an ImageList control, which manages the images (icons or bitmaps) that are displayed on the Toolbar buttons. For the present project, just use text buttons. I presented information on using the ImageList control in Chapter 7. Before you start to work on the Toolbar buttons, set the Align property of the Toolbar to Top, causing the Toolbar to position itself automatically at the top of the container form, filling it from side to side. This property must be set in the regular Visual Basic properties windownot in the Toolbars pop-up property sheet, which you use next. The Toolbar is an object with its own properties, and it contains several Button objects with their own properties. When a Toolbar control is selected on the Visual Basic design screen, the Properties window displays the Toolbars properties, which control variables such as the button size and font. To access Button properties and add or delete buttons, you need to display the Toolbars property sheet by right-clicking on the control and selecting Properties from the menu that is displayed. The Toolbar Control properties pageanother name for dialog boxis shown in Figure 22.4.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |