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 >
Wrap
BASIC Source File
|
1993-01-29
|
2KB
|
55 lines
' +----------------------------------------------------------------------+
' | |
' | BASWIZ Copyright (c) 1990-1993 Thomas G. Hanlin III |
' | |
' | The BASIC Wizard's Library |
' | |
' +----------------------------------------------------------------------+
DECLARE FUNCTION FracReduce$(Nr AS STRING)
DEFINT A-Z
FUNCTION FracSet$ (NumSt$)
Num$ = LTRIM$(NumSt$)
tmp = INSTR(Num$, ".")
IF tmp THEN
L& = CLNG(VAL(LEFT$(Num$, tmp - 1)))
tmp1 = 9 - LEN(MID$(STR$(L&), 2))
IF tmp1 > 0 THEN
St$ = MID$(Num$, tmp + 1, tmp1)
tmp1 = LEN(St$)
L& = CLNG(VAL(STR$(L&) + St$))
R& = CLNG(VAL("1" + STRING$(tmp1, "0")))
ELSE
R& = 1&
END IF
ELSE
tmp = INSTR(Num$, " ")
IF tmp THEN
W& = CLNG(VAL(LEFT$(Num$, tmp - 1)))
Num$ = MID$(Num$, tmp + 1)
ELSE
W& = 0&
END IF
tmp = INSTR(Num$, "/")
IF tmp THEN
L& = CLNG(VAL(LEFT$(Num$, tmp - 1)))
R& = CLNG(VAL(MID$(Num$, tmp + 1, 9)))
ELSE
L& = CLNG(VAL(Num$))
R& = 1&
END IF
L& = W& * R& + L&
END IF
IF R& < 0& THEN
L& = -L&
R& = -R&
END IF
IF R& = 0& THEN
FracSet$ = ""
ELSE
FracSet$ = FracReduce$(MKL$(L&) + MKL$(R&))
END IF
END FUNCTION