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

  1. *****************************************************************
  2. FUNCTION CHKZIP (statecode, zipcode)
  3. *****************************************************************
  4.  
  5. * Verify range of first five characters of U.S. Zip Codes
  6.  
  7. * Copyright(c) 1991 -- James Occhiogrosso
  8.  
  9. LOCAL old_area := 0
  10.  
  11. * If passed statecode exceeds 2 characters, exit
  12. IF LEN(TRIM(statecode)) > 2
  13.     RETURN(.T.)
  14. ENDIF
  15.  
  16. * Save current area and select Zip Code file
  17. old_area = SELECT()
  18. SELECT zips
  19.  
  20. * Make sure Zip Code database is available
  21. IF EMPTY(ALIAS())
  22.     IF FILE('zips.dbf')
  23.         * If Zips file exists, open it
  24.         SELECT 0
  25.         USE zips
  26.     ELSE
  27.         * Otherwise, exit
  28.         RETURN(.T.)
  29.     ENDIF
  30. ENDIF
  31.  
  32. * If ZIPS pointer is not on correct state, move it
  33. IF UPPER(SUBSTR(statecode,1,2)) != zips->state
  34.    LOCATE FOR UPPER(TRIM(statecode)) $ zips->state
  35. ENDIF
  36.  
  37. * Validate first 5 digits of passed Zip Code
  38. IF LEN(TRIM(SUBSTR(zipcode,1,5))) > 4 ;
  39.    .AND. zipcode >= zips->lozip .AND. zipcode <= zips->hizip
  40.  
  41.    * Restore normal add/edit message and return
  42.    AEDMSG('mw_pgdn')
  43.    * Reselect original area and return
  44.    SELECT(old_area)
  45.    RETURN(.T.)
  46.  
  47. ELSE
  48.    * Sound an error beep
  49.    ERRORBEEP()
  50.    IF .NOT. FOUND()
  51.        AEDMSG('State not in database')
  52.    ELSE
  53.        * Otherwise, display correct range
  54.        AEDMSG('Range for ' + SUBSTR(statecode,1,2) + ' is ' + ;
  55.                 zips->lozip +  ' to ' + zips->hizip)
  56.    ENDIF
  57.  
  58.    * Reselect original area and return
  59.    SELECT(old_area)
  60.    RETURN(.F.)
  61.  
  62. ENDIF
  63.  
  64.