home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / baswiz19.zip / BW$BAS.ZIP / FRACSET.BAS < prev    next >
BASIC Source File  |  1993-01-29  |  2KB  |  55 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        BASWIZ  Copyright (c) 1990-1993  Thomas G. Hanlin III         |
  4. '   |                                                                      |
  5. '   |                      The BASIC Wizard's Library                      |
  6. '   |                                                                      |
  7. '   +----------------------------------------------------------------------+
  8.  
  9.    DECLARE FUNCTION FracReduce$(Nr AS STRING)
  10.  
  11.    DEFINT A-Z
  12.  
  13. FUNCTION FracSet$ (NumSt$)
  14.    Num$ = LTRIM$(NumSt$)
  15.    tmp = INSTR(Num$, ".")
  16.    IF tmp THEN
  17.       L& = CLNG(VAL(LEFT$(Num$, tmp - 1)))
  18.       tmp1 = 9 - LEN(MID$(STR$(L&), 2))
  19.       IF tmp1 > 0 THEN
  20.          St$ = MID$(Num$, tmp + 1, tmp1)
  21.          tmp1 = LEN(St$)
  22.          L& = CLNG(VAL(STR$(L&) + St$))
  23.          R& = CLNG(VAL("1" + STRING$(tmp1, "0")))
  24.       ELSE
  25.          R& = 1&
  26.       END IF
  27.    ELSE
  28.       tmp = INSTR(Num$, " ")
  29.       IF tmp THEN
  30.          W& = CLNG(VAL(LEFT$(Num$, tmp - 1)))
  31.          Num$ = MID$(Num$, tmp + 1)
  32.       ELSE
  33.          W& = 0&
  34.       END IF
  35.       tmp = INSTR(Num$, "/")
  36.       IF tmp THEN
  37.          L& = CLNG(VAL(LEFT$(Num$, tmp - 1)))
  38.          R& = CLNG(VAL(MID$(Num$, tmp + 1, 9)))
  39.       ELSE
  40.          L& = CLNG(VAL(Num$))
  41.          R& = 1&
  42.       END IF
  43.       L& = W& * R& + L&
  44.    END IF
  45.    IF R& < 0& THEN
  46.       L& = -L&
  47.       R& = -R&
  48.    END IF
  49.    IF R& = 0& THEN
  50.       FracSet$ = ""
  51.    ELSE
  52.       FracSet$ = FracReduce$(MKL$(L&) + MKL$(R&))
  53.    END IF
  54. END FUNCTION
  55.