home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / database / p4w_all.zip / TI1280.ASC < prev    next >
Text File  |  1993-03-11  |  9KB  |  331 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1280
  9.   VERSION  :  1.0
  10.        OS  :  WIN
  11.      DATE  :  March 11, 1993                           PAGE  :  1/5
  12.  
  13.     TITLE  :  Parsing Out Parts of a Phone Field Using a Script
  14.  
  15.  
  16.  
  17.  
  18.   Intended Audience
  19.   Users with a general knowledge of Paradox for Windows.
  20.  
  21.   Prerequisites
  22.   Experience in restructuring tables.  Previous experience with
  23.   ObjectPAL is helpful.
  24.  
  25.   Purpose
  26.   This document demonstrates a script with a scan loop that will
  27.   store portions of a phone number field formatted as (###)###-####
  28.   into another field.  This script may be useful for formatting
  29.   phone numbers so they can be used in a dialer program, or perhaps
  30.   just to have an unformatted data source.  It provides a good
  31.   example of general string parsing.
  32.  
  33.   The script that appears on the next page will parse an
  34.   alphanumeric phone number field into unformatted data.  The
  35.   script will put the new string into another field in your
  36.   database.  Several formatting options are presented in the script
  37.   that you can choose from depending on your needs.  The options in
  38.   the script are:
  39.  
  40.      Option 1: Place the area code into another field with a
  41.                minimum size of 3 characters.
  42.  
  43.      Option 2: Place the prefix into another field with a minimum
  44.                size of 3 characters.
  45.  
  46.      Option 3: Place the last four digits of the phone number into
  47.                another field with a minimum size of 4.
  48.  
  49.      Option 4: Place the phone number without the "-" and without
  50.                the area code into another field with a minimum size
  51.                of 7 characters.
  52.  
  53.      Option 5: Place only the numbers of a phone number field into
  54.                another field (with a minimum size of 10
  55.                characters), stripping out '(', ')' and '-'.
  56.    
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1280
  75.   VERSION  :  1.0
  76.        OS  :  WIN
  77.      DATE  :  March 11, 1993                           PAGE  :  2/5
  78.  
  79.     TITLE  :  Parsing Out Parts of a Phone Field Using a Script
  80.  
  81.  
  82.  
  83.  
  84.   To use the script, you will need to have an alphanumeric field in
  85.   your table to hold the value of the string that was created from
  86.   your phone number field (one of the options discussed above).
  87.   Depending on the option that you choose, this field will need to
  88.   have a specific size.  The required field sizes for each option
  89.   are listed on the previous page.  If you don't already have a
  90.   field to hold this string, you will need to first Restructure
  91.   your table and add a new field to your table.
  92.  
  93.   NOTE: Before making global changes to your table, it is a good
  94.         idea to first make a backup copy.
  95.  
  96.  
  97.   To add a new field to your table:
  98.  
  99.       o  Choose File | Utilities | Restructure, select your table
  100.          from the Select File dialog box, then choose OK.
  101.  
  102.       o  Add a new field to your table, give it a name, declare it
  103.          as an alphanumeric type with a size that corresponds to
  104.          the option that you want to select (i.e. 10 characters for
  105.          an unformatted phone number with area code, prefix and
  106.          number, such as 4084399096).
  107.  
  108.       o  Choose Save
  109.  
  110.   Creating the script:
  111.  
  112.   Choose File | New | Script.  Type in the lines of code shown on
  113.   the following page.  You will need to customize the script and
  114.   substitute your own table name for TBLNAME and field names for
  115.   SOURCEFLD (the phone number field) and NEWFLD.  In this script
  116.   example, only one parsing option can be used for the entire
  117.   script.  To select a particular parsing option, you will need to
  118.   remove the ";" that precedes the option (see the comments in the
  119.   script).
  120.    
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1280
  141.   VERSION  :  1.0
  142.        OS  :  WIN
  143.      DATE  :  March 11, 1993                           PAGE  :  3/5
  144.  
  145.     TITLE  :  Parsing Out Parts of a Phone Field Using a Script
  146.  
  147.  
  148.  
  149.  
  150.     Var
  151.        Tc1           Tcursor
  152.        a, b, c, d    String
  153.        Tv            Tableview
  154.     EndVar
  155.  
  156.     Tc1.open("TBLNAME")             ;ADD YOUR DATABASE NAME HERE
  157.     Tc1.edit()                      ; AND ENCLOSE IT IN QUOTES
  158.  
  159.     scan Tc1 :                      ;Make sure you type the colon.
  160.  
  161.        a=Tc1."SOURCEFLD"            ;Store Field value into
  162.                                     ; variable 'a'. Enclose the
  163.                                     ; field name in quotes.
  164.  
  165.        if a.match("(..)..-..", b, c, d) then
  166.  
  167.        ; UNREMARK ONE OF THE OPTIONS BELOW BY REMOVING THE ';'
  168.        ;   THAT PRECEDES THE OPTION (i.e. Tc1.NEWFLD = b)
  169.  
  170.           ;Tc1.NEWFLD = b           ;Put area code into new field
  171.           ;Tc1.NEWFLD = c           ;Put prefix into new field
  172.           ;Tc1.NEWFLD = d           ;Put last 4 digits into new
  173.                                     ; field.
  174.           ;Tc1.NEWFLD = c+d         ;Put phone number w/o "-" and
  175.                                     ; area code into new field
  176.           ;Tc1.NEWFLD = b+c+d       ;Put only numbers into new
  177.                                     ; field, stripping out '(', ')'
  178.                                     ; and '-'.
  179.  
  180.        endif
  181.  
  182.     endscan
  183.  
  184.     Tc1.close()                     ;Close your TCursor
  185.     Tv.open("TBLNAME")              ;Open file in table view to
  186.                                     ; review changes
  187.  
  188.   NOTE: The semicolon ";" indicates that a comment follows.  The
  189.         comment will not be processed when you play the script.
  190.    
  191.   This script scans each record of the table and uses the match
  192.   method to test if the the value in the phone number field matches
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1280
  207.   VERSION  :  1.0
  208.        OS  :  WIN
  209.      DATE  :  March 11, 1993                           PAGE  :  4/5
  210.  
  211.     TITLE  :  Parsing Out Parts of a Phone Field Using a Script
  212.  
  213.  
  214.  
  215.  
  216.   the pattern: "(..)..-..".  The ".." stands for a wildcard and
  217.   matches any number of characters (including none).  If a match is
  218.   found, Paradox will parse the field according to the particular
  219.   parsing option that you select (see the discussion on page 2).
  220.   If a match is not found, Paradox will leave the NEWFLD blank.
  221.  
  222.   Depending on the format of your phone number field, you may need
  223.   to modify the string that is in the match method.  The string
  224.   that is used in the match method in the script example,
  225.   "(..)..-..", looks for a phone number of the format
  226.   (###)###-####.  If your phone number has the format
  227.   (###) ###-#### or ###-###-####, modify the match method as
  228.   follows:
  229.  
  230.         Format           Change match method to
  231.  
  232.         (###) ###-####   if a.match("(..) ..-..", b, c, d) then
  233.         ###-###-####     if a.match("..-..-..", b, c, d) then
  234.  
  235.  
  236.   Checking the script for syntax errors: 
  237.  
  238.   After you have typed in the script on the previous page, choose
  239.   Language | Check Syntax from the menu.  The compiler examines the
  240.   code and identifies if there are syntax errors in the method by
  241.   displaying a message in the status line of the open Editor
  242.   window, such as "No syntax errors" or a description of the syntax
  243.   error.  If there is a syntax error, Paradox positions the cursor
  244.   at the point of the first error.  Before you can run the script,
  245.   you will need to correct your code and choose Language | Check
  246.   Syntax again until there are no remaining syntax errors.
  247.    
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1280
  273.   VERSION  :  1.0
  274.        OS  :  WIN
  275.      DATE  :  March 11, 1993                           PAGE  :  5/5
  276.  
  277.     TITLE  :  Parsing Out Parts of a Phone Field Using a Script
  278.  
  279.  
  280.  
  281.  
  282.   When there are no syntax errors:
  283.  
  284.      1.  Choose File | Save, type in a filename in the edit box,
  285.          then choose OK.
  286.  
  287.      2.  To run the script, choose the Lightning Bolt tool.  Your
  288.          script will play, and display your table in View mode.
  289.  
  290.      3.  To view your table, click on the table Title bar.
  291.  
  292.  
  293.   Suggested Reading:
  294.  
  295.   scan statement         ObjectPAL Reference Guide, Chapter 3
  296.   match method           ObjectPAL Reference Guide, Chapter 4
  297.   Restructuring Tables   User's Guide, Chapter 9
  298.  
  299.  
  300.   DISCLAIMER: You have the right to use this technical information
  301.   subject to the terms of the No-Nonsense License Statement that
  302.   you received with the Borland product to which this information
  303.   pertains.
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.