home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 13 / CD_ASCQ_13_0494.iso / maj / 419 / phone.bas < prev    next >
BASIC Source File  |  1994-03-13  |  2KB  |  62 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        PBClone  Copyright (c) 1990-1994  Thomas G. Hanlin III        |
  4. '   |                                                                      |
  5. '   +----------------------------------------------------------------------+
  6.  
  7. FUNCTION Phone2Num& (PhoneNumber$)
  8.    FOR tmp% = 1 TO LEN(PhoneNumber$)
  9.       ch$ = UCASE$(MID$(PhoneNumber$, tmp%, 1))
  10.       IF ch$ >= "A" AND ch$ <= "Z" THEN
  11.          foo% = INSTR("ABCDEFGHIJKLMNOPRSTUVWXY", ch$)
  12.          IF foo% THEN
  13.             ch$ = MID$("222333444555666777888999", foo%, 1)
  14.          ELSE
  15.             ch$ = "bogus"
  16.          END IF
  17.       END IF
  18.       IF ch$ >= "0" AND ch$ <= "9" THEN foo$ = foo$ + ch$
  19.    NEXT
  20.    IF LEN(foo$) = 11 AND LEFT$(foo$, 1) = "1" THEN foo$ = MID$(foo$, 2)
  21.    IF LEN(foo$) = 4 OR LEN(foo$) = 7 OR LEN(foo$) = 10 THEN
  22.       foo$ = RIGHT$(STRING$(10, "0") + foo$, 10)
  23.       IF MID$(foo$, 2, 1) = "1" THEN
  24.          Negate% = -1
  25.       ELSEIF MID$(foo$, 2, 1) = "0" THEN
  26.          Negate% = 1
  27.       ELSE
  28.          Wrong% = -1
  29.       END IF
  30.       PhoneNr& = CLNG(VAL(LEFT$(foo$, 1) + MID$(foo$, 3)))
  31.    ELSE
  32.       Wrong% = -1
  33.    END IF
  34.    IF Wrong% THEN
  35.       Phone2Num& = -1&
  36.    ELSE
  37.       Phone2Num& = Negate% * PhoneNr&
  38.    END IF
  39. END FUNCTION
  40.  
  41. FUNCTION Num2Phone$ (Number&)
  42.    IF Number& = -1& THEN
  43.       Num2Phone$ = ""
  44.       EXIT FUNCTION
  45.    ELSEIF Number& < 0& THEN
  46.       Nr& = -Number&
  47.       Midget$ = "1"
  48.    ELSE
  49.       Nr& = Number&
  50.       Midget$ = "0"
  51.    END IF
  52.    foo$ = RIGHT$(STRING$(9, "0") + LTRIM$(STR$(Nr&)), 9)
  53.    foo$ = LEFT$(foo$, 1) + Midget$ + MID$(foo$, 2)
  54.    IF LEFT$(foo$, 6) = "000000" THEN
  55.       Num2Phone$ = RIGHT$(foo$, 4)
  56.    ELSEIF LEFT$(foo$, 3) = "000" THEN
  57.       Num2Phone$ = RIGHT$(foo$, 7)
  58.    ELSE
  59.       Num2Phone$ = foo$
  60.    END IF
  61. END FUNCTION
  62.