22 08 2IR4G43MVDJKI3ZCAZY2YTUFOF6JE3NFZAUKYNI




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




Coding The Wines Form
The code for the Wines form is a bit more complicated. As for handling the Command Buttons, follow the exact same procedure as you did for the Customers form, including the use of chameleon Command Buttons. The code for this event procedure is shown in Listing 22.3.

Listing 22.3 The Command1_Click event procedure in WINES.FRM.


Private Sub Command1_Click(Index As Integer)

Dim Reply As Integer

Select Case Index
Case 0 ‘ Add New or Save.
If EnteringRecord Then ‘ Save command.
‘ Save the new record.
Adodc1.Recordset.Update
EnteringRecord = False
‘ Relock the StockNo TextBox.
Text1(0).Locked = True
‘ Change command buttons.
Command1(0).Caption = “&Add New”
Command1(1).Caption = “&Delete Current”
‘ Enable the ADO Data control.
Adodc1.Enabled = True
Adodc1.Recordset.Requery
Adodc1.Recordset.MoveLast
‘ Enable List and Finished buttons.
Command1(2).Enabled = True
Command1(3).Enabled = True
Else ‘ Add New command.
EnteringRecord = True
‘ Unlock the StockNo Text Box.
Text1(0).Locked = False
‘ Put focus in first text box.
Text1(0).SetFocus
‘ Disable List and Finished buttons.
Command1(2).Enabled = False
Command1(3).Enabled = False
‘ Change command buttons.
Command1(0).Caption = “&Save”
Command1(1).Caption = “&Cancel”
‘ Disable the data control.
Adodc1.Enabled = False
‘ Add a new record.
Adodc1.Refresh
Adodc1.Recordset.AddNew
End If
Case 1 ‘ Delete current or Cancel.
If EnteringRecord Then ‘ Cancel command.
Reply = MsgBox(“Discard current entry?”, vbYesNo + vbQuestion, _ “Cancel Entry”)
If Reply = vbNo Then Exit Sub
Adodc1.Recordset.CancelUpdate
Adodc1.Refresh
Adodc1.Enabled = True
‘ Relock the StockNo TextBox.
Text1(0).Locked = True
EnteringRecord = False
‘ Enable List and Finished buttons.
Command1(2).Enabled = True
Command1(3).Enabled = True
Command1(0).Caption = “&Add New”
Command1(1).Caption = “&Delete Current”
Else ‘ Delete Current command.
Reply = MsgBox(“Delete this record?”, vbYesNo + vbQuestion, _ “Cancel Entry”)
If Reply = vbNo Then Exit Sub
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
End If
Case 2 ‘ List all.
frmList.Caption = “Wines Table”
frmList.Adodc1.ConnectionString = frmWines.Adodc1.ConnectionString
frmList.Adodc1.RecordSource = frmWines.Adodc1.RecordSource
frmList.Adodc1.Refresh
frmList.Show
Case 3 ‘ Finished.
Hide
End Select

End Sub


The Wines form is different, because the Combo Box controls that are used for entry of the Color and Type data must be loaded with the appropriate choices, in order for those choices to be available when the user displays the form. Place this code in the Form_Load event procedure, as shown in Listing 22.4. Another method is to load each Combo Box from a text file that is kept in the same directory as the database, or from a dedicated table within the database itself. In fact, this method is preferable for a commercial program, because this method permits changes to the Color and Type lists without modifying the source code and recompiling the program—editing the text file is all that is needed.
Listing 22.4 The Form_Load event procedure in WINES.FRM.


Private Sub Form_Load()

‘ Load the Combo boxes.

ComboColor.AddItem “red”
ComboColor.AddItem “white”
ComboColor.AddItem “rose”
ComboColor.AddItem “dessert”
ComboColor.AddItem “sparkling”

ComboType.AddItem “Chardonnay”
ComboType.AddItem “Pinot noir”
ComboType.AddItem “Burgundy”
ComboType.AddItem “Pinot blanc”
ComboType.AddItem “Barolo”
ComboType.AddItem “Barbaresco”
ComboType.AddItem “Cabernet”
ComboType.AddItem “Semillion”
ComboType.AddItem “Bordeaux”
ComboType.AddItem “Chateauneuf de Pape”
ComboType.AddItem “White zinfandel”
ComboType.AddItem “Champagne”
Adodc1.Refresh

End Sub


Coding The List Form
Coding the List form is very simple, because most of the form’s work is already handled by the DataGrid control—all that functionality is built right in, so you don’t have to do a thing. (Aren’t software components great?) However, you do need to add a little code. In the Form_Resize event procedure, you need to adjust the control sizes; this code is shown in Listing 22.5. Note that you are concerned only with the height of the DataGrid control; when you set its Align property to vbAlignTop, it is automatically positioned at the top of the form and is sized to match the form’s width.
Listing 22.5 The Form_Resize event procedure in LIST1.FRM.


Private Sub Form_Resize()

‘ Set size and position of controls.

DataGrid1.Height = ScaleHeight - Command1.Height
Command1.Top = ScaleHeight - Command1.Height
Command1.Left = 0
Command1.Width = ScaleWidth

End Sub


The only other code required for the List form is to place the single line of code



Hide


in the Command Button’s Click event procedure. By hiding the List form, you automatically return to the form that called it—the Customers form or the Wines form—which had remained inactive in the background while the List form was displayed.
What Now?
The answer to that one is easy: Try it out. Now you have a partially functional database front end to take on a trial run. Watch for error messages; if any appear, check your code to be sure that you entered everything properly. Currently, the program gives you the capability to add new records to the Customers and Wines tables, edit and delete existing records, and view a list of all records in either table. Note that changes to the table data made in List view are saved, providing another way for the user to edit table data.

You’re off to a good start. But clearly, you have a long road ahead before you have a fully functional program.



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-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.



Wyszukiwarka

Podobne podstrony:
22 08 2012
ANT SPCC (09 08 15 22 39)
TI 00 08 22 T pl(2)
22 04 08 sem IX
Mój portfel z 22 sierpnia 08 (nr 164)
Nowe prawo z 22 grudnia 08 (nr 249)
TI 00 08 22 T pl(2)
Biznes i zdrowie z 22 lipca 08 (nr 142)
08 (22)
TI 97 08 22 GT T B F U pl(2)
Biznes i energia z 22 grudnia 08 (nr 249)
TI 00 08 22 T pl(1)

więcej podobnych podstron