home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MAKETABL.ZIP / MAKETABL.PRG
Encoding:
Text File  |  1987-07-01  |  2.1 KB  |  69 lines

  1. PROCEDURE MAKETABL
  2. *****************************************************************************
  3. * SYNTAX:   DO MAKETABL WITH "Alias", "Key", "TABLE-FILENAME"               *
  4. * AUTHOR:   Thomas G. Pantazi                            *
  5. * VERSION:  1.2                                 *
  6. * LAST MOD: 7/1/87 - TGP                            *
  7. *                                        *
  8. * PURPOSE:  Create a table of every unique 'Key' in a database. This is     *
  9. *        frequently necessary when doing data entry validation.        *
  10. *                                        *
  11. * MEMVARS:  Alias    - The Alias name assigned to the work area containing  *
  12. *               the USEd database to be searched.            *
  13. *        Key      - The field name to be searched.  File is not required *
  14. *               to be indexed, but if it is the index is assumed to  *
  15. *               be opened. Each INDEXKEY is checked to find a match. *
  16. *               if no match is found an index is created.        *
  17. *        TablName - The name to be given to the result database.        *
  18. *                                        *
  19. * NOTES:    This routine uses work area number 10, therefore if you have    *
  20. *        files open in this area, you should modify the work area used   *
  21. *        here. It is also assumed that you will reopen any indices that  *
  22. *        were open prior to execution of this routine.            *
  23. *                                        *
  24. *****************************************************************************
  25.  
  26. PARAMETERS Alias,Key,TablName
  27. KeyName  = Key
  28. KeyField = &Alias->&Key
  29. KeyLen     = LEN("KeyField")
  30. KeyType  = TYPE("KeyField")
  31. KeyFound = .F.
  32. I     = 1
  33.  
  34. SELECT &Alias
  35. DO WHILE .NOT. KeyFound
  36.    IF INDEXKEY(I) = ""
  37.       INDEX ON &Key TO TEMP$$$$
  38.       KeyFound=.T.
  39.    ENDIF
  40.    IF INDEXKEY(I) = Key
  41.       KeyFound=.T.
  42.       SET ORDER TO I
  43.    ENDIF
  44.    I = I + 1
  45. ENDDO
  46. SELECT 10
  47. CREATE TABLE$$$
  48. APPEND BLANK
  49. REPLACE FIELD_NAME WITH "&KeyName", FIELD_TYPE WITH KeyType, FIELD_LEN WITH KeyLen
  50. USE
  51. CREATE &TablName FROM TABLE$$$
  52. SELECT &Alias
  53. MKey=&Key
  54. DO WHILE .NOT. EOF()
  55.    DO WHILE MKey = &Key
  56.       SKIP
  57.    ENDDO
  58.    SELECT 10
  59.    APPEND BLANK
  60.    REPLACE &Key WITH MKey
  61.    SELECT &Alias
  62.    MKey = &Key
  63. ENDDO
  64. DELETE FILE TABLE$$$.DBF
  65. SELECT &TablName
  66. USE
  67. SELECT &Alias
  68. RETURN
  69.