home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / database / p4w_all.zip / TI1493.ASC < prev    next >
Text File  |  1993-05-12  |  7KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1493
  9.   VERSION  :  1.0
  10.        OS  :  WIN
  11.      DATE  :  May 12, 1993                             PAGE  :  1/4
  12.  
  13.     TITLE  :  Performing a Search and Replace of a Character
  14.  
  15.  
  16.  
  17.  
  18.   Intended Audience:
  19.   Beginning ObjectPAL users
  20.  
  21.   Prerequisites:
  22.   Some familiarity with ObjectPAL is helpful
  23.  
  24.   Purpose of the TI:
  25.   This document will illustrate how you can use ObjectPAL to search
  26.   for the occurrence of a specific character and replace it with
  27.   another character for each record in a table.
  28.  
  29.  
  30.   It is often desirable to search for every occurrence of a
  31.   specific character and replace it with another character for each
  32.   record in a table.  For example, suppose you have a table named
  33.   "Test" that has an Alphanumeric field called ID with 3 records,
  34.   as shown below, and you want to replace all occurrences of a
  35.   comma (,) with periods (.).
  36.  
  37.  
  38.        TEST═╦════ID═════╗
  39.             ║123,567    ║
  40.             ║1,234,567  ║
  41.             ║1,234      ║
  42.  
  43.  
  44.   With a small table like this, it is easy to modify each record
  45.   manually.  But with a big table (e.g. over 1000 records), it is
  46.   not going to be very efficient.  ObjectPAL automates the process.
  47.   On the following page is an example script which will perform the
  48.   search and replace quickly.  The script performs a search and
  49.   replace on the "ID" field of the table "Test".  Information on
  50.   how to create and run a script follows at the end of this
  51.   document.
  52.  
  53.    
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1493
  75.   VERSION  :  1.0
  76.        OS  :  WIN
  77.      DATE  :  May 12, 1993                             PAGE  :  2/4
  78.  
  79.     TITLE  :  Performing a Search and Replace of a Character
  80.  
  81.  
  82.  
  83.  
  84.   EXAMPLE 1
  85.  
  86.        method run(var eventInfo Event)
  87.  
  88.        var
  89.             oldstring      String
  90.             newstring      String
  91.             tc             TCursor
  92.             ar             Array[] String
  93.             tv             TableView
  94.        endVar
  95.    
  96.        tc.open("TEST.DB")           ;open TCursor for "TEST.DB"
  97.        tc.edit()                    ;begin edit mode
  98.        scan tc:                     ;start scan loop
  99.             newstring = ""          ;Initialize newstring
  100.             ;--pass the value of ID field to variable oldstring
  101.             ;--use breakApart() to split oldstring to an array of
  102.             ;--substrings
  103.             oldstring = tc."ID"
  104.             oldstring.breakApart(ar,",")
  105.             ;--concatenate the array of substrings to newstring
  106.    
  107.             for i from 1 to ar.size()
  108.               if i <> ar.size()       ;replace comma with period
  109.                 then newstring = newstring + ar[i] + "."
  110.                 else newstring = newstring + ar[i]
  111.               endIf
  112.             endFor
  113.             ;--pass the value of newstring to ID field
  114.             tc."ID" = newstring
  115.        endScan
  116.        tc.close()                   ;close TCursor
  117.        tv.open("TEST.DB")           ;view the table "TEST.DB"
  118.        tv.bringToTop()
  119.        endmethod
  120.  
  121.  
  122.   NOTE: The semicolon ";" indicates that a comment follows.  The
  123.         comment will not be processed when when you play the
  124.         script.
  125.  
  126.    
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1493
  141.   VERSION  :  1.0
  142.        OS  :  WIN
  143.      DATE  :  May 12, 1993                             PAGE  :  3/4
  144.  
  145.     TITLE  :  Performing a Search and Replace of a Character
  146.  
  147.  
  148.  
  149.  
  150.   EXAMPLE 2
  151.  
  152.   A variation on this script removes the "," entirely.  The
  153.   modified code would be:
  154.  
  155.        method run(var eventInfo Event)
  156.        var
  157.             oldstring      String
  158.             newstring      String
  159.             tc             TCursor
  160.             ar             Array[] String
  161.             tv             TableView
  162.        endvar
  163.  
  164.        tc.open("TEST.DB")           ;open TCursor
  165.        tc.edit()                    ;begin edit mode
  166.        scan tc:                     ;start scan loop
  167.             newstring = ""          ;Initialize newstring
  168.             ;--pass the value of ID field to variable oldstring
  169.             ;--use breakApart() to split oldstring to an array of
  170.             ;--substring
  171.             oldstring = tc."ID"
  172.             oldstring.breakApart(ar,",")
  173.             ;--concatenated the array of substrings to newstring
  174.  
  175.             for i from 1 to ar.size()
  176.               newstring = newstring + ar[i]
  177.             endFor
  178.             ;--pass the value of newstring to ID field
  179.             tc."ID" = newstring
  180.        endscan
  181.        tc.close()                   ;close TCursor
  182.        tv.open("TEST.DB")           ;open the table "TEST.DB"
  183.        tv.bringToTop()
  184.        endmethod
  185.  
  186.  
  187.   To Create the Scripts Shown in Example 1 and Example 2:
  188.  
  189.   Choose File | New | Script from the Desktop.  Type the ObjectPAL
  190.   code that appears in either Example 1 or Example 2.
  191.    
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1493
  207.   VERSION  :  1.0
  208.        OS  :  WIN
  209.      DATE  :  May 12, 1993                             PAGE  :  4/4
  210.  
  211.     TITLE  :  Performing a Search and Replace of a Character
  212.  
  213.  
  214.  
  215.  
  216.   Check the Syntax
  217.  
  218.   After you have typed in the script for either Example 1 or
  219.   Example 2, choose Language | Check Syntax from the Desktop.  The
  220.   compiler examines the code and identifies if there are syntax
  221.   errors.  It displays a message in the status line of the open
  222.   Editor window, such as "No syntax errors" or a description of the
  223.   syntax error.  If there is a syntax error, Paradox positions the
  224.   cursor at the point of the first error.  Before you can run the
  225.   script, you will need to correct your code and choose Language |
  226.   Check Syntax again until there are no remaining syntax errors.
  227.  
  228.  
  229.   When there are no syntax errors:
  230.  
  231.      1.  Choose File | Save from the Desktop, type in a filename in
  232.          the edit box, then choose OK.
  233.  
  234.      2.  To run the script, press [F8].  Your script will play, and
  235.          display your table in View mode.
  236.  
  237.  
  238.   Each of these examples demonstrate the reformatting of text using
  239.   basic ObjectPAL methods.  Many text formatting problems can be
  240.   resolved using these same functions in similar methods.
  241.  
  242.  
  243.   Suggested Reading:
  244.  
  245.   scan           Chapter 3, ObjectPAL Reference manual
  246.   subStr         Chapter 4, ObjectPAL Reference manual
  247.   breakApart     Chapter 4, ObjectPAL Reference manual
  248.   TCursor        Chapter 10, ObjectPAL Developer's Guide
  249.  
  250.  
  251.   DISCLAIMER: You have the right to use this technical information
  252.   subject to the terms of the No-Nonsense License Statement that
  253.   you received with the Borland product to which this information
  254.   pertains.
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.