Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Wrapping It Up: Validation Code And The Invoices Form
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
Use the Insert Form command to add a new form to the project. Set the forms Caption property to Select Wine and its name to frmSelectWine. The BorderStyle property should be Fixed Single. Then, add the following controls to the form and set their properties as indicated:
ADO Data control:
ConnectionString:
(to GRAPEVINE as before)
Name:
AdodcWines
RecordSource:
Select * from wines order by description
Visible:
False
Caption:
Wines
DataList control:
Name:
DataList1
ListField:
Description
BoundColumn:
StockNo
RowSource:
AdodcWines
Text Box:
Name:
txtQuantity
Text:
(blank string)
Command Button (in a control array):
Index:
0
Caption:
&OK
Command Button (in a control array):
Index:
1
Caption:
&Cancel
For the DataList control, you set the ListField property to Description, so that the control displays the wine descriptions. You also set the BoundColumn property to StockNo, so that the BoundText property returns the StockNo value for the selected wine. Finally, you need to add two label controls to identify the DataList control and the Text Box. When you finish designing this form, it should look something like Figure 23.2.
The only initialization step required for this form is to set the value in the Quantity Text Box; this is done in the forms Load event procedure. You use a default value of 12, because that is the most commonly ordered quantity of wine. As a convenience, when the user selects a wine by clicking on it in the DataList control, you will move the focus to the txtQuantity box. These procedures are shown in Listing 23.5.
Listing 23.5 The Select Wine forms Load and DataList1_Click event procedures.
Private Sub Form_Load()
txtQuantity.Text = 12
End Sub
Private Sub DataList1_Click()
txtQuantity.SetFocus
End Sub
Finally, this form needs a procedure for the Command Buttons. If the user selects the Cancel button, code sets the value in the Quantity Text Box to zero. This signals the calling function that the user canceled (as youll see later). If the user selects a wine and then clicks on OK, several steps must be performed:
1. Verify that a wine has been selected and a quantity entered.
2. Copy the quantity value from the txtQuantity box on the Select Wine form to the txtQuantity Text Box on the Invoices form.
Figure 23.2 The Select Wine form.
3. Copy the StockNo value from the DataList controls BoundText property to the txtStockNo Text Box on the Invoices form.
4. Enable the Save button on the Invoices form. This button was previously disabled because, before any wines were selected, you had nothing to save.
5. Hide the Select Wine form.
The code for the Select Wine forms Command Buttons Click event procedure is presented in Listing 23.6.
Listing 23.6 The Click event procedure for the Select Wine forms Command Buttons.
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0 OK
Be sure data has been entered.
If DataListWines.BoundText = Or txtQuantity.Text = Then
MsgBox (You must select a wine and specify a quantity.)
txtQuantity.SetFocus
Exit Sub
End If
Copy the data for the selected wine to
the Invoices form.
frmInvoice.txtStockNo.Text = DataListWines.BoundText
frmInvoice.txtQuantity.Text = txtQuantity.Text
Enable the Save button on the Invoices form.
frmInvoice.Command1(0).Enabled = True
Hide the SelectWine form.
Hide
Case 1 Cancel, as indicated by this Text Box being 0.
frmInvoice.txtQuantity.Text =
Hide
End Select
Connecting To The Invoices Table
Because the main purpose of this form is to enter orders or invoices, it must be connected to the Invoices table in your database, which is your next step. To illustrate how to access a database without the ADO Data control, you will use ADO objects and code only for this task.
You need to do two things with the Invoices table. First, when a user starts a new invoice, you need to add a new record to the table representing the new invoice. In addition, you need to get the InvNo value that is assigned to this record automatically by the database engine. This value is needed for new records in the Items table, to associate each item (wine) with the corresponding invoice. Second, you need to consider what happens if the user cancels the entry of a new invoice. Good database design requires that the associated record in the Invoices table be deleted.
I wrote a single function to perform both of these tasks. Called CreateNewInvoice, it takes a single argument named Delete. If Delete is zero, the function adds a new record to the Invoices table, using values for CustID, CustPO, and Date that are obtained from the Invoices form. The InvNo value of the newly added record is then saved in the global variable InvoiceNumber, so that it is available to the code that adds new records to the Items table. If passed a non-zero value as its argument, the function deletes the record in the Invoices table that has that InvNo value.
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:
23 05MIKROBIOLOGIA JAMY USTNEJ, WYKŁAD 7, 23 05 2013Konwencja Wiedeńska o Prawie Traktatów (23 05 1969)2014 05 23 paths reserve currency renminbiv 05 2305 00 23 anhig6lr6ie4becmqm7ewfhbhbbkwmhtaypbhdyTI 97 05 23 GT pl(1)TI 02 05 23 T pl(1)więcej podobnych podstron