home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / basic / strtonum.bas < prev    next >
Encoding:
BASIC Source File  |  1989-11-09  |  1006 b   |  36 lines

  1. DECLARE FUNCTION Filter$ (Txt$, FilterString$)
  2.  
  3. ' Input a line:
  4. LINE INPUT "Enter a number with commas: "; A$
  5.  
  6. ' Look only for valid numeric characters (0123456789.-)
  7. ' in the input string:
  8. CleanNum$ = Filter$(A$, "0123456789.-")
  9.  
  10. ' Convert the string to a number:
  11. PRINT "The number's value = "; VAL(CleanNum$)
  12. END
  13.  
  14. ' ========================== FILTER =======================
  15. '         Takes unwanted characters out of a string by
  16. '         comparing them with a filter string containing
  17. '         only acceptable numeric characters
  18. ' =========================================================
  19.  
  20. FUNCTION Filter$ (Txt$, FilterString$) STATIC
  21.    Temp$ = ""
  22.    TxtLength = LEN(Txt$)
  23.  
  24.    FOR I = 1 TO TxtLength     ' Isolate each character in
  25.       C$ = MID$(Txt$, I, 1)   ' the string.
  26.  
  27.       ' If the character is in the filter string, save it:
  28.       IF INSTR(FilterString$, C$) <> 0 THEN
  29.          Temp$ = Temp$ + C$
  30.       END IF
  31.    NEXT I
  32.  
  33.    Filter$ = Temp$
  34. END FUNCTION
  35.  
  36.