home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tech91.zip / TI662.ASC < prev    next >
Text File  |  1991-08-26  |  5KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Paradox                                NUMBER  :  662
  9.   VERSION  :  2,3,3.5
  10.        OS  :  PC DOS
  11.      DATE  :  August 26, 1991                          PAGE  :  1/3
  12.  
  13.     TITLE  :  Generating Unique Values (Multi User Auto Increment)
  14.  
  15.  
  16.  
  17.  
  18.   ;            This Method Works for Single or Multi User
  19.  
  20.  
  21.   ;Borrowed in part from the Paradox 3 Developers Toolkit.
  22.  
  23.   ;Special Notes : This procedure is very useful for entering a
  24.   ;                new identification number for every new record
  25.   ;                entered into for instance a "Customer" table.
  26.   ;                Because Paradox doesn't have its own auto-
  27.   ;                incrementing feature, this procedure does the
  28.   ;                "trick" for you.  Create a one field KEYED
  29.   ;                table such as:
  30.   ;
  31.   ;                             Counter ═╦═ Counter ═╗
  32.   ;                                      ║   10001   ║
  33.   ;                                      ║   10002   ║
  34.   ;                                      ║   10003   ║
  35.   ;                                      ║   10004   ║
  36.   ;                                      ║   10005   ║
  37.   ;                                      ║   10006   ║
  38.   ;                                      ║   10007   ║
  39.   ;                                      ║   10008   ║
  40.   ;                                      ║   10009   ║
  41.   ;                                      ║   10010   ║
  42.   ;
  43.   ;                Upon pressing a designated key, the value
  44.   ;                10001 is transferred to your "Customer" table
  45.   ;                and the value 10001 is changed to 10011.  The
  46.   ;                table is keyed so 10011 goes to the bottom of
  47.   ;                the table and the next available number is
  48.   ;                ready at the top of the table for next time.
  49.  
  50.   ; First define a counting procedure and then a user interaction
  51.   ; for entering data.
  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                                NUMBER  :  662
  75.   VERSION  :  2,3,3.5
  76.        OS  :  PC DOS
  77.      DATE  :  August 26, 1991                          PAGE  :  2/3
  78.  
  79.     TITLE  :  Generating Unique Values (Multi User Auto Increment)
  80.  
  81.  
  82.  
  83.  
  84.   ;-----define the procedure COUNTER ----------------------------
  85.  
  86.   PROC counter()
  87.    PRIVATE countervar,begintbl
  88.  
  89.     begintbl=Table()
  90.     MOVETO "counter"  ; On a multitable form the MOVETO command
  91.                       ; here would not work unless the the counter
  92.                       ; table were placed on the multitable form.
  93.                       ; You could place the counter table as an
  94.                       ; unlinked table on the form and the
  95.                       ; MOVETO command would still work.  No need
  96.                       ; in this context to first VIEW "counter".
  97.  
  98.     SCAN ; move through table until you can successfully lock
  99.           ; a record.  Ten records in your counter table will give
  100.           ; you ten chances to successfully lock a record.
  101.  
  102.       LOCKRECORD
  103.         IF NOT retval THEN
  104.                 ; NOT retval means could not get a lock, so
  105.            LOOP ; go to top of scan loop which goes to next record
  106.         ELSE
  107.            countervar = [Counter]
  108.            [Counter] = [Counter] + 10
  109.  
  110.           ; If you have ten records in your counter table then
  111.           ; increment the current record by ten.  With twenty
  112.           ; records in your counter table increment by twenty,
  113.           ; etc.
  114.  
  115.            UNLOCKRECORD
  116.            QUITLOOP
  117.         ENDIF
  118.     ENDSCAN
  119.  
  120.     MOVETO begintbl
  121.     RETURN countervar
  122.   ENDPROC
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Paradox                                NUMBER  :  662
  141.   VERSION  :  2,3,3.5
  142.        OS  :  PC DOS
  143.      DATE  :  August 26, 1991                          PAGE  :  3/3
  144.  
  145.     TITLE  :  Generating Unique Values (Multi User Auto Increment)
  146.  
  147.  
  148.  
  149.  
  150.   ;------ Having already defined a counter proc, now set up the
  151.   ;       workspace with the counter and customer tables.  If
  152.   ;       using a multitable form no need to VIEW "counter", but
  153.   ;       rather place "counter" as an embedded non-linked table
  154.   ;       within a "customer" master form.
  155.  
  156.  
  157.   VIEW "counter"
  158.   COEDIT "customer"
  159.  
  160.  
  161.   ;------start the wait interaction with user--------------------
  162.  
  163.   WHILE true    ; start a continuous loop
  164.      WAIT table
  165.       PROMPT "Press [F2] When done,  Press [Ins] for a new Record",
  166.              ""
  167.       UNTIL "F2", "Ins"  ; Define other keys as you see fit.
  168.                          ; The system variable retval will be equal
  169.                          ; to the key you pressed.
  170.  
  171.      SWITCH
  172.        CASE retval="F2"  : DO_IT!
  173.                            QUITLOOP ;this is only way out of loop
  174.  
  175.        CASE retval="Ins" : END
  176.                            DOWN ; in form view use CTRLPGDN
  177.                                 ; opens a new record
  178.                            [cust id]=COUNTER()
  179.                                 ; place the result of the counter
  180.                                 ; procedure into [cust id]
  181.      ENDSWITCH
  182.   ENDWHILE  ;loop back to the WHILE command
  183.  
  184.   CLEARALL CLEAR
  185.  
  186.   ;===============================================================
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.