home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1993 #2
/
Image.iso
/
database
/
p4w_all.zip
/
TI1367.ASC
< prev
next >
Wrap
Text File
|
1993-04-23
|
5KB
|
199 lines
PRODUCT : Paradox for Windows NUMBER : 1367
VERSION : 1.0
OS : WIN
DATE : April 23, 1993 PAGE : 1/3
TITLE : Example ObjectPAL Method to Automate Data Entry Into
a Phone Number Field
Intended Audience
Beginning ObjectPAL users
Prerequisites
Knowledge of form design. A table containing an alphanumeric
field which is used to store phone numbers. A form to allow data
entry into the above mentioned table. Familiarity with ObjectPAL
is helpful.
Purpose of the TI
This document demonstrates an example of an ObjectPAL depart
method that can be used 1) to speed up data entry, and 2) as an
alternative to picture statements in a table. This code, once
attached to the depart method of a field, will automate filling
in the "("'s and "-"'s while performing error checking.
It is often desirable to automate the way data is entered into a
field in a database to provide data consistency. Phone number
data is one example of data that users could enter in several
different formats. If you want the data to conform to a
particular format, you can either use picture statements or you
can use ObjectPAL. This document demonstrates a technique of
using an ObjectPAL depart method to automate data entry of phone
number data so that the phone number data is formatted with
parentheses, "(" and ")", and/or hyphens, "-". Specifically, the
code will check to see how many, and which, characters the user
has typed and format the phone number accordingly. Below are
some examples of how the depart method will handle data that is
entered into a phone number field:
User Types Upon Depart Field
1234567 123-4567
8001234567 (800) 123-4567
18001234567 1-(800)-123-4567
28001234567 ERROR
1234 ERROR
To use the depart method, inspect (right-click) on the Phone
Number field while in design mode on your form. Choose Methods
from the menu. Choose Depart from the Built-in Methods list.
Choose OK. Make your method resemble the code on the following
page:
PRODUCT : Paradox for Windows NUMBER : 1367
VERSION : 1.0
OS : WIN
DATE : April 23, 1993 PAGE : 2/3
TITLE : Example ObjectPAL Method to Automate Data Entry Into
a Phone Number Field
method depart(var eventInfo MoveEvent)
eventInfo.SetErrorCode(can_depart)
Switch
Case self.size() = 7:
self.value = self.substr(1,3) + "-" + self.substr(4,4)
Case self.size() = 10:
self.value = "(" + self.substr(1,3) + ") " +
self.substr(4,3) + "-" + self.substr(7,4)
Case self.size() = 11 and self.substr(1,1) = "1":
self.value = "1-" + "(" + self.substr(2,3) +
")-" + self.substr(5,3) + "-" + self.substr(8,4)
Otherwise: msginfo("Error","Invalid Phone Number!")
eventInfo.setErrorCode(cannotDepart)
EndSwitch
Endmethod
NOTE: The lines that include the "eventInfo.setErrorCode()"
method will not permit the user to move off the field if
they have not entered a valid phone number. You can remove
these two lines if you want to warn the user but still
allow them to leave the field.
Check the syntax
After you have typed in the code shown above, choose Language |
Check Syntax. The compiler examines the code and identifies if
there are syntax errors in the method by displaying a message in
the status line of the open Editor window, such as "No syntax
errors" or a description of the syntax error. If there is a
syntax error, Paradox positions the cursor at the point of the
first error. Before you can run the form, you will need to
correct your code and choose Language | Check Syntax again until
there are no remaining syntax errors.
When there are no syntax errors:
1. Choose File | Save, to save the changes to your form.
2. To run the form, press [F8].
PRODUCT : Paradox for Windows NUMBER : 1367
VERSION : 1.0
OS : WIN
DATE : April 23, 1993 PAGE : 3/3
TITLE : Example ObjectPAL Method to Automate Data Entry Into
a Phone Number Field
Suggested Reading:
depart method Chapter 2, ObjectPAL Reference Guide,
Chapter 6, ObjectPAL Developer's Guide
substr method Chapter 4, ObjectPAL Reference Guide
size method Chapter 4, ObjectPAL Reference Guide
switch Chapter 2, ObjectPAL Developer's Guide
setErrorCode Chapter 4, ObjectPAL Reference Guide,
Chapter 13, ObjectPAL Developer's Guide
DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.