home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_NODUPL.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  1.6 KB  |  66 lines

  1. *****************************************************************
  2. FUNCTION NODUPL (key_mvar, look_index, key_field, user_func)
  3. *****************************************************************
  4.  
  5. * Tests key field and displays message if duplicate value exists
  6.  
  7. * Copyright(c) 1991 -- James Occhiogrosso
  8.  
  9. # include "inkey.ch"
  10.  
  11. LOCAL old_help := IF(TYPE('helpcode') = 'C', helpcode, ''), ;
  12.       old_ndx := INDEXORD(), old_recd := RECNO(),           ;
  13.       ret_value := .T.
  14.  
  15. IF PCOUNT() < 3
  16.     * Error in calling syntax
  17.     RETURN(.F.)
  18. ENDIF
  19.  
  20. IF PCOUNT() = 4
  21.     * If a user function is passed, execute it
  22.     &user_func()
  23. ENDIF
  24.  
  25. IF TYPE('helpcode') = 'C' .AND. UPPER(helpcode) = 'EDIT'   ;
  26.                           .AND. key_mvar = key_field
  27.     * Allow key variable to remain unchanged when editing
  28.     RETURN(.T.)
  29. ENDIF
  30.  
  31. * Check for a duplicate key value
  32. SET ORDER TO look_index
  33. SEEK key_mvar
  34.  
  35. IF FOUND()
  36.     * We have a duplicate keyfield
  37.     ret_value = .F.
  38.     ERRORBEEP()
  39.     helpcode = "DUPLICATE"
  40.  
  41.     * If AEDBAR is in use, display "duplicate" message, and
  42.     * ask operator if reentry of data is desired.
  43.  
  44.     IF TYPE('aedbar') = 'L' .AND. aedbar
  45.         * Display the "duplicate" message
  46.         AEDMSG('mw_dupkey')
  47.  
  48.         IF OPCONFIRM()
  49.             * Operator wants to reenter
  50.             AEDMSG('mw_pgdn')
  51.             ret_value = .F.
  52.         ELSE
  53.             * Operator wants to abort
  54.             AEDMSG('mw_init')
  55.             * Stuff keyboard with Esc to abort READ
  56.             KEYBOARD CHR(K_ESC)
  57.         ENDIF
  58.     ENDIF
  59. ENDIF
  60.  
  61. helpcode = old_help
  62. GOTO old_recd
  63. SET ORDER TO old_ndx
  64. RETURN(ret_value)
  65.  
  66.