home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1993 #2
/
Image.iso
/
database
/
p4w_all.zip
/
TI1280.ASC
< prev
next >
Wrap
Text File
|
1993-03-11
|
9KB
|
331 lines
PRODUCT : Paradox for Windows NUMBER : 1280
VERSION : 1.0
OS : WIN
DATE : March 11, 1993 PAGE : 1/5
TITLE : Parsing Out Parts of a Phone Field Using a Script
Intended Audience
Users with a general knowledge of Paradox for Windows.
Prerequisites
Experience in restructuring tables. Previous experience with
ObjectPAL is helpful.
Purpose
This document demonstrates a script with a scan loop that will
store portions of a phone number field formatted as (###)###-####
into another field. This script may be useful for formatting
phone numbers so they can be used in a dialer program, or perhaps
just to have an unformatted data source. It provides a good
example of general string parsing.
The script that appears on the next page will parse an
alphanumeric phone number field into unformatted data. The
script will put the new string into another field in your
database. Several formatting options are presented in the script
that you can choose from depending on your needs. The options in
the script are:
Option 1: Place the area code into another field with a
minimum size of 3 characters.
Option 2: Place the prefix into another field with a minimum
size of 3 characters.
Option 3: Place the last four digits of the phone number into
another field with a minimum size of 4.
Option 4: Place the phone number without the "-" and without
the area code into another field with a minimum size
of 7 characters.
Option 5: Place only the numbers of a phone number field into
another field (with a minimum size of 10
characters), stripping out '(', ')' and '-'.
PRODUCT : Paradox for Windows NUMBER : 1280
VERSION : 1.0
OS : WIN
DATE : March 11, 1993 PAGE : 2/5
TITLE : Parsing Out Parts of a Phone Field Using a Script
To use the script, you will need to have an alphanumeric field in
your table to hold the value of the string that was created from
your phone number field (one of the options discussed above).
Depending on the option that you choose, this field will need to
have a specific size. The required field sizes for each option
are listed on the previous page. If you don't already have a
field to hold this string, you will need to first Restructure
your table and add a new field to your table.
NOTE: Before making global changes to your table, it is a good
idea to first make a backup copy.
To add a new field to your table:
o Choose File | Utilities | Restructure, select your table
from the Select File dialog box, then choose OK.
o Add a new field to your table, give it a name, declare it
as an alphanumeric type with a size that corresponds to
the option that you want to select (i.e. 10 characters for
an unformatted phone number with area code, prefix and
number, such as 4084399096).
o Choose Save
Creating the script:
Choose File | New | Script. Type in the lines of code shown on
the following page. You will need to customize the script and
substitute your own table name for TBLNAME and field names for
SOURCEFLD (the phone number field) and NEWFLD. In this script
example, only one parsing option can be used for the entire
script. To select a particular parsing option, you will need to
remove the ";" that precedes the option (see the comments in the
script).
PRODUCT : Paradox for Windows NUMBER : 1280
VERSION : 1.0
OS : WIN
DATE : March 11, 1993 PAGE : 3/5
TITLE : Parsing Out Parts of a Phone Field Using a Script
Var
Tc1 Tcursor
a, b, c, d String
Tv Tableview
EndVar
Tc1.open("TBLNAME") ;ADD YOUR DATABASE NAME HERE
Tc1.edit() ; AND ENCLOSE IT IN QUOTES
scan Tc1 : ;Make sure you type the colon.
a=Tc1."SOURCEFLD" ;Store Field value into
; variable 'a'. Enclose the
; field name in quotes.
if a.match("(..)..-..", b, c, d) then
; UNREMARK ONE OF THE OPTIONS BELOW BY REMOVING THE ';'
; THAT PRECEDES THE OPTION (i.e. Tc1.NEWFLD = b)
;Tc1.NEWFLD = b ;Put area code into new field
;Tc1.NEWFLD = c ;Put prefix into new field
;Tc1.NEWFLD = d ;Put last 4 digits into new
; field.
;Tc1.NEWFLD = c+d ;Put phone number w/o "-" and
; area code into new field
;Tc1.NEWFLD = b+c+d ;Put only numbers into new
; field, stripping out '(', ')'
; and '-'.
endif
endscan
Tc1.close() ;Close your TCursor
Tv.open("TBLNAME") ;Open file in table view to
; review changes
NOTE: The semicolon ";" indicates that a comment follows. The
comment will not be processed when you play the script.
This script scans each record of the table and uses the match
method to test if the the value in the phone number field matches
PRODUCT : Paradox for Windows NUMBER : 1280
VERSION : 1.0
OS : WIN
DATE : March 11, 1993 PAGE : 4/5
TITLE : Parsing Out Parts of a Phone Field Using a Script
the pattern: "(..)..-..". The ".." stands for a wildcard and
matches any number of characters (including none). If a match is
found, Paradox will parse the field according to the particular
parsing option that you select (see the discussion on page 2).
If a match is not found, Paradox will leave the NEWFLD blank.
Depending on the format of your phone number field, you may need
to modify the string that is in the match method. The string
that is used in the match method in the script example,
"(..)..-..", looks for a phone number of the format
(###)###-####. If your phone number has the format
(###) ###-#### or ###-###-####, modify the match method as
follows:
Format Change match method to
(###) ###-#### if a.match("(..) ..-..", b, c, d) then
###-###-#### if a.match("..-..-..", b, c, d) then
Checking the script for syntax errors:
After you have typed in the script on the previous page, choose
Language | Check Syntax from the menu. 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 script,
you will need to correct your code and choose Language | Check
Syntax again until there are no remaining syntax errors.
PRODUCT : Paradox for Windows NUMBER : 1280
VERSION : 1.0
OS : WIN
DATE : March 11, 1993 PAGE : 5/5
TITLE : Parsing Out Parts of a Phone Field Using a Script
When there are no syntax errors:
1. Choose File | Save, type in a filename in the edit box,
then choose OK.
2. To run the script, choose the Lightning Bolt tool. Your
script will play, and display your table in View mode.
3. To view your table, click on the table Title bar.
Suggested Reading:
scan statement ObjectPAL Reference Guide, Chapter 3
match method ObjectPAL Reference Guide, Chapter 4
Restructuring Tables User's Guide, Chapter 9
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.