home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / PBC22B.ZIP / PBC$BAS.ZIP / FMTPHONE.BAS < prev    next >
BASIC Source File  |  1993-04-18  |  1KB  |  36 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        PBClone  Copyright (c) 1990-1993  Thomas G. Hanlin III        |
  4. '   |                                                                      |
  5. '   +----------------------------------------------------------------------+
  6.  
  7.    DECLARE FUNCTION AscM% (St$, BYVAL Posn%)
  8.    DECLARE FUNCTION UpcaseI% (BYVAL Ch%)
  9.  
  10. FUNCTION FormatPhone$ (RawSt$)
  11.  
  12.    '--- toss any characters that aren't alphanumeric, 'n' also Q and Z
  13.    st$ = ""
  14.    FOR tmp% = 1 TO LEN(RawSt$)
  15.       ch% = UpcaseI%(AscM%(RawSt$, tmp%))
  16.       IF ch% >= 48 AND ch% <= 57 OR ch% >= 65 AND ch% < 90 AND ch% <> 81 THEN
  17.          st$ = st$ + CHR$(ch%)
  18.       END IF
  19.    NEXT
  20.  
  21.    '--- format the result based on the string length
  22.    IF LEN(st$) = 11 AND LEFT$(st$, 1) = "1" THEN
  23.       st$ = MID$(st$, 2)
  24.    END IF
  25.    SELECT CASE LEN(st$)
  26.       CASE 4
  27.          FormatPhone$ = st$
  28.       CASE 7
  29.          FormatPhone$ = LEFT$(st$, 3) + "-" + RIGHT$(st$, 4)
  30.       CASE 10
  31.          FormatPhone$ = "(" + LEFT$(st$, 3) + ") " + MID$(st$, 4, 3) + "-" + RIGHT$(st$, 4)
  32.       CASE ELSE
  33.          FormatPhone$ = ""
  34.    END SELECT
  35. END FUNCTION
  36.