home *** CD-ROM | disk | FTP | other *** search
- 'Date: 01-22-92 (21:54)
- 'From: TOM HANLIN
- '---------------------------------------------------------------------------
- ' just for the heck of it... the source for the PBClone 1.7 routine
- ' to convert a decimal number to any number base (2-35). Set Number$
- ' to STRING$(16, "0") on entry; use NumberLen to trim (via RIGHT$) on
- ' exit if you don't want any leading zeros. NumberLen = -1 on error.
- DEFINT A-Z
- SUB Dec2Any (DecimalNumber, NumberBase, Number$, NumberLen)
- Num& = CVL(MKI$(DecimalNumber) + STRING$(2, 0))
- Result$ = ""
- IF NumberBase < 2 OR NumberBase > 35 THEN
- NumberLen = -1
- EXIT SUB
- END IF
- DO
- NextNum& = Num& \ CLNG(NumberBase)
- Digit = Num& - NextNum& * CLNG(NumberBase)
- IF Digit < 10 THEN
- Digit$ = CHR$(ASC("0") + Digit)
- ELSE
- Digit$ = CHR$(ASC("A") + Digit - 10)
- END IF
- Result$ = Digit$ + Result$
- Num& = NextNum&
- LOOP WHILE Num& > 0&
- IF LEN(Result$) > LEN(Number$) THEN
- NumberLen = -1
- ELSE
- NumberLen = LEN(Result$)
- MID$(Number$, LEN(Number$) - NumberLen + 1) = Result$
- END IF
- END SUB
-