home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / TEXT / PDX_ALL.ZIP / TI662.ASC < prev    next >
Text File  |  1991-12-20  |  7KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. PRODUCT  :  Paradox                                      NUMBER  :  662
  8. VERSION  :  2.0 & up
  9.      OS  :  DOS
  10.    DATE  :  December 20, 1991                              PAGE  :  1/4
  11.  
  12.   TITLE  :  How to Use PAL to Generate Unique Values
  13.            (Auto-increment)
  14.  
  15.  
  16.  
  17.  
  18. ┌───────────────────────────────────────────────────────────────┐
  19. │                                                               │
  20. │ This Technical Information Sheet is intended only for users   │
  21. │ who are familiar with PAL.  It contains PAL code to demon-    │
  22. │ strate a model solution to a specific problem and is not      │
  23. │ intended to represent a complete programming solution.        │
  24. │ Programmers who use this code must take responsibility for    │
  25. │ debugging and developing their application.  Assistance       │
  26. │ in debugging and developing applications is considered        │
  27. │ consulting and is beyond the scope of technical support.      │
  28. │                                                               │
  29. └───────────────────────────────────────────────────────────────┘
  30.  
  31. In many cases, you will want to generate unique values for each new
  32. record in a table.  For example, each new customer might need a new ID
  33. number.  Here are three different methods for creating an auto-
  34. increment capability.
  35.  
  36. The code samples here are generic examples only, and should be modified
  37. to fit your specific application.  Note: the following methods work
  38. only in Edit and Coedit modes.
  39.  
  40. For a single user in interactive mode, the following method works.
  41.  
  42.                      SETKEY -23  [] = IMAGECMAX()+1
  43.  
  44. Whenever the user presses <ALT-I>, the current field becomes equal to
  45. one more than the current maximum in the current column.  To use this
  46. command, insert the above command into the script INIT using the menu
  47. choices: Scripts | Editor | Write.  Next type in "Init" and press
  48. <ENTER>.  Type in the above command exactly as it appears.  INIT is
  49. played every time you start Paradox, thus activating <ALT-I>.  The
  50. keycode -23 corresponds to the key <ALT-I>.  For more keycodes, see
  51. Appendix B of the PAL User's Guide.  Also the cursor must be in the
  52. field to incremented, which must be numeric.
  53.  
  54. The following is an example of a PAL program that increments a field.
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. PRODUCT  :  Paradox                                      NUMBER  :  662
  74. VERSION  :  2.0 & up
  75.      OS  :  DOS
  76.    DATE  :  December 20, 1991                              PAGE  :  2/4
  77.  
  78.   TITLE  :  How to use PAL to Generate Unique Values
  79.            (Auto-increment)
  80.  
  81.  
  82.  
  83.  
  84.        IF ISEMPTY("CUST") THEN
  85.           [CUST ID] = 1
  86.        ENDIF
  87.  
  88.        WHILE TRUE
  89.        IF ISBLANK([CUST ID]) THEN
  90.           [Cust ID] = CMAX("Cust","Cust ID") + 1
  91.        ENDIF
  92.  
  93.                WAIT RECORD
  94.                UNTIL "F2", "INS" ...
  95.                KEYPRESS RETVAL
  96.                SWITCH
  97.                    CASE RETVAL = "F2":
  98.                    .
  99.                    .
  100.                    .
  101.                ENDSWITCH
  102.        ENDWHILE
  103.  
  104. (For more information on the PAL WAIT RECORD command see Technical
  105. Information Sheets 538 and 697)
  106.  
  107. Whenever the user moves to a record where the CUST ID is blank, the
  108. application enters in a new ID number.  The new ID number is derived
  109. using the CMAX function which returns the highest number.   The
  110. application then increments this number by one.
  111.  
  112. The previous two methods work fine in a single-user environment,
  113. however if there is a possibility the application might be used on a
  114. network, you should use the following method.  Note: the following
  115. method works only in Coedit mode.
  116.  
  117. First, create a table with a single Numeric field.  For example:
  118.  
  119.       ID ═╦═══ ID ═══╗
  120.           ║   10001  ║
  121.  
  122. This table contains the next number to be used when the application
  123. increments the field in the table you are entering data.
  124.  
  125. Whenever the user moves to a record where the CUST ID is blank, a new
  126. record is created and filled in with a new ID number.  The main data
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. PRODUCT  :  Paradox                                      NUMBER  :  662
  140. VERSION  :  2.0 & up
  141.      OS  :  DOS
  142.    DATE  :  December 20, 1991                              PAGE  :  3/4
  143.  
  144.   TITLE  :  How to use PAL to Generate Unique Values
  145.            (Auto-increment)
  146.  
  147.  
  148.  
  149.  
  150. entry routine calls a procedure that moves to the ID table, and
  151. attempts to lock the record.  If it fails the first time, it keeps
  152. attempting to lock the record until it succeeds.  During these
  153. attempts, no one else can access the number there.  This method
  154. guarantees that each user obtains a unique number.
  155.  
  156. When the application succeeds in locking the number, it increments it
  157. by one so the next time the application accesses a the table a new
  158. number is available.  Next, the application moves back to the CUST
  159. table to continue the editing.
  160.  
  161. The ID table must be on the workspace in order to access it.  If data
  162. entry occurs in table view or with a single table form, you must place
  163. the ID table on the workspace before editing your data table.
  164.  
  165. A multi-table form complicates the process of accessing the ID table.
  166. (In a multi-table form it is not possible to toggle to table view
  167. before posting the current record.)   The simplest solution is to place
  168. the ID table into your master form as an unlinked embedded form, with
  169. the foreground color the same color as the background to hide it from
  170. the users.  With the ID table embedded on the master table, the
  171. application can access the ID table while remaining in form view.
  172.  
  173. The following procedure is an example of how to access the ID table to
  174. obtain the next ID number.
  175.  
  176.    PROC GetCustID()
  177.    PRIVATE id
  178.        CurrTab = TABLE()
  179.        MOVETO "ID"
  180.        LOCKRECORD              ;Give only one user access
  181.        WHILE NOT RETVAL        ;Keep trying if first attempt
  182.            SLEEP 10            ;fails
  183.            LOCKRECORD
  184.        ENDWHILE
  185.        id = [ID]
  186.        [ID] = [ID] + 1         ;Increment ID
  187.        UNLOCKRECORD            ;Allow other users access
  188.        MOVETO CurrTab
  189.        RETURN id
  190.    ENDPROC
  191.  
  192. The following PAL program is an example of the main data entry routine.
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205. PRODUCT  :  Paradox                                      NUMBER  :  662
  206. VERSION  :  2.0 & up
  207.      OS  :  DOS
  208.    DATE  :  December 20, 1991                              PAGE  :  4/4
  209.  
  210.   TITLE  :  How to use PAL to Generate Unique Values
  211.            (Auto-increment)
  212.  
  213.  
  214.  
  215.  
  216.    WHILE TRUE
  217.  
  218.        IF ISBLANK([Cust ID]) THEN
  219.            [Cust ID] = GetCustID()
  220.        ENDIF
  221.  
  222.        WAIT RECORD
  223.        UNTIL "F2", "INS" ...
  224.  
  225.        SWITCH
  226.            CASE RETVAL = "F2"  :
  227.          .
  228.          .
  229.          .
  230.        ENDSWITCH
  231.  
  232.    ENDWHILE
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.