home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / database / p4w_all.zip / TI1367.ASC < prev    next >
Text File  |  1993-04-23  |  5KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1367
  8.   VERSION  :  1.0
  9.        OS  :  WIN
  10.      DATE  :  April 23, 1993                           PAGE  :  1/3
  11.  
  12.     TITLE  :  Example ObjectPAL Method to Automate Data Entry Into
  13.               a Phone Number Field
  14.  
  15.  
  16.  
  17.  
  18.   Intended Audience
  19.   Beginning ObjectPAL users
  20.  
  21.   Prerequisites
  22.   Knowledge of form design.  A table containing an alphanumeric
  23.   field which is used to store phone numbers.  A form to allow data
  24.   entry into the above mentioned table.  Familiarity with ObjectPAL
  25.   is helpful.
  26.  
  27.   Purpose of the TI
  28.   This document demonstrates an example of an ObjectPAL depart
  29.   method that can be used 1) to speed up data entry, and 2) as an
  30.   alternative to picture statements in a table.  This code, once
  31.   attached to the depart method of a field, will automate filling
  32.   in the "("'s and "-"'s while performing error checking.
  33.  
  34.  
  35.   It is often desirable to automate the way data is entered into a
  36.   field in a database to provide data consistency.  Phone number
  37.   data is one example of data that users could enter in several
  38.   different formats.  If you want the data to conform to a
  39.   particular format, you can either use picture statements or you
  40.   can use ObjectPAL.  This document demonstrates a technique of
  41.   using an ObjectPAL depart method to automate data entry of phone
  42.   number data so that the phone number data is formatted with
  43.   parentheses, "(" and ")", and/or hyphens, "-".  Specifically, the
  44.   code will check to see how many, and which, characters the user
  45.   has typed and format the phone number accordingly.  Below are
  46.   some examples of how the depart method will handle data that is
  47.   entered into a phone number field:
  48.  
  49.        User Types                    Upon Depart Field
  50.        1234567                       123-4567
  51.        8001234567                    (800) 123-4567
  52.        18001234567                   1-(800)-123-4567
  53.        28001234567                   ERROR
  54.        1234                          ERROR
  55.  
  56.   To use the depart method, inspect (right-click) on the Phone
  57.   Number field while in design mode on your form.  Choose Methods
  58.   from the menu.  Choose Depart from the Built-in Methods list.
  59.   Choose OK.  Make your method resemble the code on the following
  60.   page:
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1367
  74.   VERSION  :  1.0
  75.        OS  :  WIN
  76.      DATE  :  April 23, 1993                           PAGE  :  2/3
  77.  
  78.     TITLE  :  Example ObjectPAL Method to Automate Data Entry Into
  79.               a Phone Number Field
  80.  
  81.  
  82.  
  83.  
  84.   method depart(var eventInfo MoveEvent)
  85.  
  86.   eventInfo.SetErrorCode(can_depart)
  87.   Switch
  88.       Case self.size() = 7:
  89.          self.value = self.substr(1,3) + "-" + self.substr(4,4)
  90.       Case self.size() = 10:
  91.          self.value = "(" + self.substr(1,3) + ") " +
  92.          self.substr(4,3) + "-" + self.substr(7,4)
  93.       Case self.size() = 11 and self.substr(1,1) = "1":
  94.          self.value = "1-" + "(" + self.substr(2,3) +
  95.             ")-" + self.substr(5,3) + "-" + self.substr(8,4)
  96.       Otherwise: msginfo("Error","Invalid Phone Number!")
  97.                  eventInfo.setErrorCode(cannotDepart)
  98.   EndSwitch
  99.  
  100.   Endmethod
  101.  
  102.   NOTE: The lines that include the "eventInfo.setErrorCode()"
  103.         method will not permit the user to move off the field if
  104.         they have not entered a valid phone number.  You can remove
  105.         these two lines if you want to warn the user but still
  106.         allow them to leave the field.
  107.  
  108.   Check the syntax
  109.  
  110.   After you have typed in the code shown above, choose Language |
  111.   Check Syntax.  The compiler examines the code and identifies if
  112.   there are syntax errors in the method by displaying a message in
  113.   the status line of the open Editor window, such as "No syntax
  114.   errors" or a description of the syntax error.  If there is a
  115.   syntax error, Paradox positions the cursor at the point of the
  116.   first error.  Before you can run the form, you will need to
  117.   correct your code and choose Language | Check Syntax again until
  118.   there are no remaining syntax errors.
  119.  
  120.   When there are no syntax errors:
  121.  
  122.      1.  Choose File | Save, to save the changes to your form.
  123.  
  124.      2.  To run the form, press [F8].
  125.  
  126.    
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1367
  140.   VERSION  :  1.0
  141.        OS  :  WIN
  142.      DATE  :  April 23, 1993                           PAGE  :  3/3
  143.  
  144.     TITLE  :  Example ObjectPAL Method to Automate Data Entry Into
  145.               a Phone Number Field
  146.  
  147.  
  148.  
  149.  
  150.   Suggested Reading:
  151.  
  152.   depart method       Chapter 2, ObjectPAL Reference Guide,
  153.                       Chapter 6, ObjectPAL Developer's Guide
  154.   substr method       Chapter 4, ObjectPAL Reference Guide
  155.   size method         Chapter 4, ObjectPAL Reference Guide
  156.   switch              Chapter 2, ObjectPAL Developer's Guide
  157.   setErrorCode        Chapter 4, ObjectPAL Reference Guide,
  158.                       Chapter 13, ObjectPAL Developer's Guide
  159.  
  160.  
  161.   DISCLAIMER: You have the right to use this technical information
  162.   subject to the terms of the No-Nonsense License Statement that
  163.   you received with the Borland product to which this information
  164.   pertains.
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.