23 01 N3KPIMD5Z3HU7JVOOE4SB3ARBC7Z7VDWIE2QTAI




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




Chapter 23Wrapping It Up: Validation Code And The Invoices Form


The final steps in our database project are to write data validation code and to design the form for creating invoices.
A well-written program does everything it can to prevent errors. Certain types of errors are impossible to prevent—you can’t control when a disk drive is going to crash, for example. Other errors can be avoided, particularly errors in data entry. Knowing something about the data that belongs in a particular field allows you to verify that new or edited data meets the required criteria. You start this chapter by writing validation code to handle this data-verification task, and then you begin creating a more complicated form for the database program: the Invoice Entry form. You then will have a functional—though admittedly bare-bones—relational database.
Validation Code
You can take any one of several approaches to validating data in a database front end. In some cases, only one of these approaches will work, while at other times, you can use whichever approach you prefer. Remember, the important thing is not how you validate the data, but that you do validate the data.

Blocking Keystrokes
One validation method simply prevents the entry of inappropriate keystrokes into a Text Box, thus preventing the entry of invalid data in the first place. For example, in a ZIP code field, you know that only the 10 numerical digits are permitted (plus a hyphen if 9-digit ZIP codes are allowed). You can use the Text Box’s KeyPress event procedure to filter keystrokes. This procedure receives a type Integer argument named KeyAscii, which contains the numerical code of the key that was pressed. Code in the procedure can examine this value and determine whether it is one of the allowed keys. If it is not permitted, setting the KeyAscii argument to zero cancels the keystroke, preventing it from reaching the underlying control. For example, the following code permits entry of the digits zero through nine only, beeping if any other key is pressed. In all cases, you must pass through the Backspace character (KeyAscii value of eight), or else users will not be able to use the Backspace key toerase characters. Here’s the code:


Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 8 Then Exit Sub

If KeyAscii < 48 Or KeyAscii > 57 Then
Beep
KeyAscii = 0
End If

End Sub



TIP:  ANSI Codes
Keyboard and other characters are represented internally by ANSI codes (also known as ASCII codes), with numeric values in the range of 0 through 255, representing each character. The KeyPress event procedure receives as its argument the ANSI code of the p

Wyszukiwarka

Podobne podstrony:
Genetyka 5 (23 01 2013)
Podstawy rekreacji ćwiczenia 23 01 10x
ZNK 23 01
r 23 01
fiszki 01 23 i 24
Stromlaufplan Passat 23 Multifunktionslenkrad ab 01 2000
WSM 01 23 pl(1)
TI 02 01 23 T B pl(2)
01 Rozpoznawanie surowców skórzanych i skórid)23

więcej podobnych podstron