10-30-2004, 11:22 PM
Quote:How about this?Yes, some feedback on your coding style:
[syntax="qbasic"]
'Omni-base converter
'Peter O'Rourke (Marinedalek) 2004
DECLARE FUNCTION reverse$ (text$)
DECLARE FUNCTION baseconv$ (basefrom%, baseto%, numfrom$)
DIM SHARED digitarray AS STRING * 36
digitarray = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
CLS
PRINT baseconv$(16, 2, "FFFF")
FUNCTION baseconv$ (basefrom%, baseto%, numfrom$)
IF baseto% <= 1 OR basefrom% < 1 OR baseto% > 36 OR basefrom% > 36 THEN baseconv$ = "0": EXIT FUNCTION
FOR position% = LEN(numfrom$) TO 1 STEP -1
tempdec& = tempdec& + (basefrom% ^ (LEN(numfrom$) - position%)) * (INSTR(digitarray, MID$(numfrom$, position%, 1)) - 1)
NEXT position%
IF baseto% = 10 THEN
baseconv$ = LTRIM$(STR$(tempdec&)) 'skip last calculation if destination is
'decimal - it 'd be a waste of time.
ELSE
DO
tempdest$ = MID$(digitarray, (tempdec& MOD baseto%) + 1, 1) + tempdest$
tempdec& = tempdec& \ baseto%
LOOP UNTIL tempdec& = 0
baseconv$ = tempdest$
END IF
END FUNCTION
FUNCTION reverse$ (text$)
FOR i% = LEN(text$) TO 1 STEP -1
temptxt$ = temptxt$ + MID$(text$, i%, 1)
NEXT i%
reverse$ = temptxt$
END FUNCTION
[/syntax]
Any feedback?
Code:
DIM SHARED digitarray AS STRING * 36
digitarray = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Code:
dim shared digitarray$
digitarray$ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Code:
tempdec& = tempdec& \ baseto%
You got all the latest color goodies, but your coding structure regarding indentation is not good. Example:
Code:
FOR i% = LEN(text$) TO 1 STEP -1
temptxt$ = temptxt$ + MID$(text$, i%, 1)
NEXT i%
As far as the technical merit of your code, I'll need to test it when I have time.
*****