plik


Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Forms And Fields, Fields And Forms function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive 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! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:   Previous Table of Contents Next Finally, set the ADO Data control’s Caption property to “Customers” and its Align property to vbAlignBottom. This last property causes the control to align itself automatically at the bottom of whatever form it is on. Now you can set the properties of the other controls on the Customers form. Generally, the properties are left at their default settings. Here are the most important changes you need to make: 1.  Set the TabStop property of the first Text Box (the one for the CustID field) to False and the Locked property to True. Because the attribute of this field was set to AutoIncrField during database design, the database engine automatically generates unique values for this field. The user doesn’t need access to this Text Box. Note that setting Locked to True prevents the user from editing the Text Box, but does not prevent you from changing it in code. Figure 22.10  Setting the RecordSource property of the ADO Data Control. 2.  For each Text Box, set the DataSource property to ADODC1 (the default name of the ADO Data control) and the DataField property to the appropriate field. Note that the DataField property offers you a drop-down list of all the fields in the Customers table. If you had not connected the ADO Data control to the data source first, this list would not be available. 3.  Set the form’s BorderStyle property to Fixed Single, so that the user can’t change its size at runtime. 4.  Be sure that the Index properties of the Command Buttons match their captions, as follows: Add New (0), Delete Current (1), List All (2), Finished (3). Save the form as CUSTOMER.FRM, and assign a Name property of “frmCustomers”. Be sure to set the form’s MDIChild property to True, to make it a child of the MDI form that you created earlier, and change the Caption property to “Customers Table”. Designing The Wines Form Conceptually, the Wines Form is quite similar to the Customers form that you just created. However, for the Wines form, you will implement one new technique: you will use a Combo Box in place of a Text Box for data entry for some of the fields. You can consider a Combo Box as a combination of a Text Box and List Box; users can either type data into the Text Box part of the control or select from the drop-down list of items. A Combo Box is appropriate when the data entry into a particular field (either usually or always) consists of an item from a predefined list. This is the case for the Color and Type fields in the Wines table. Note that using a Combo Box does not force a selection from the list—users can always type something else—but using a Combo Box does make the entry of list items faster and error-free. Select Insert Form to add a new form to the project. The form’s Name property should be set to “frmWines”, and it should be saved under the name WINES.FRM. This form will contain the following controls: •  A control array of nine Text Box controls, one for each field in the Customers table except for the Color and Type fields •  Two Combo Box controls for the Color and Type fields •  A control array of 11 Label controls, one to identify each Text Box and Combo Box •  A control array of four Command Buttons •  One ADO Data control After placing the controls, the form should look like Figure 22.11. Here are the most important changes you need to make to the form and control properties: 1.  Add the individual Text Box controls in the proper order, so that the resulting tab order is correct. You can always modify the TabIndex properties later, if necessary. Be sure to include the Combo Box controls in the desired position in the tab order. 2.  For the ADO Data control, follow the techniques previously described for the Customers form to connect it to the GRAPEVINE database and to set the RecordSource to select all records from the Wines table (SQL statement = “select * from wines”). Set the Caption property to “Wines” and the Align property to vbAlignBottom. Figure 22.11  The Wines form. 3.  For each Text Box and Combo Box, set the DataSource property to ADODC1 and the DataField property to the appropriate field. Set the Name property of the two Combo Boxes to “ComboType” and “ComboColor”. 4.  Set the form’s BorderStyle property to Fixed Single, its Caption property to “Wines Table”, and its MDIChild property to True. 5.  Make sure that the Index properties of the Command Buttons match their captions, as follows: Add New (0), Delete Current (1), List All (2), Finished (3). Designing The List Form Part of your design plan is to have the ability to list all the records in both the Wines and the Customers table. You included a List All button on both the Customers and Wines forms, but how can you implement a list of all records? The DataGrid control provides the ideal solution—it is designed for just this kind of task. You will create a single form for listing records, and then specify which table’s records are to be displayed in code before the form is displayed. Add a new form to the project. Set its Name property to “frmList” and save it as LIST1.FRM. Add one DataGrid control, one ADO Data control, and one Command Button control to the form. Set the DataGrid’s DataSource property to ADODC1 and its Align property to Top. The ADO Data control’s ConnectString should be set to the GRAPEVINE.MDB database, as you have done for the other ADO Data controls. The ADO Data control’s RecordSource property, however, doesn’t need to be set at this time, because it will be set in code. You should make the ADO Data control’s Visible property False, however, because you won’t need this control to be visible on the form. Change the Command Button’s Caption property to &Finished. Writing The Code Now that you have designed the project’s first three forms, you can turn your attention to writing the code that gives these forms their functionality. Of course, these three forms are only part of what the project requires—so why not design the remaining forms before starting on Basic code? This is one approach, but my own experience has proven that working on the project one section at a time—both forms and code—gives better results. This way, you have part of the program working properly before moving on to the next part. You can expect to have to make changes later. You already have enough forms designed to provide part of the program’s functionality, such as entering, editing, and listing records in the Customers and Wines table. Making sure that this much is working before you move on to the next challenge is a good idea. The Basic Module Complex projects such as this one almost always require a Basic module for declaration of global variables and similar tasks. To add a Basic module, select Add Module from the Project menu. Type the following code: ‘ True when entering a record, False otherwise. Global EnteringRecord As Boolean Save the module under the name GRAPEVINE (Visual Basic adds the .BAS extension). Coding The Customers Form The initial approach to coding this form is to provide its basic functions, but not necessarily everything that you eventually want it to include. You’ll write code to permit users to enter, edit, delete, and list records, and leave the code writing for data validation until later. Previous Table of Contents Next Products |  Contact Us |  About Us |  Privacy  |  Ad Info

Wyszukiwarka

Podobne podstrony:
Kanalizacje Ways 22 06 2015
FINAL EXAM ADMINISTRACJA I ROK 22 06 2013
Koncert Pytam o wolność 22 06 2007
Dyrektywa maszynowa 22 06 1998
KS guide to pronunciation (22 06 2007)
test z rozwiązaniami, prawo cywilne, cz 2, 22 06 2010
wolyn 13 06 22 prod
2007 06 22 29 Stawiarski
WSM 06 22 pl(2)
TI 00 06 22 T pl(1)
SIMR RR EGZ 2011 06 22
06 Rozdzial 22 23
06 11 09 (22)
2008 Metody obliczeniowe 06 D 2008 10 22 20 13 23
SIMR RR EGZ 2011 06 22 rozw

więcej podobnych podstron