home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / 100UTILI / LRNBAS-3.ZIP / ADVR_EX / SHARE_EX.BAS < prev    next >
BASIC Source File  |  1988-11-08  |  1KB  |  36 lines

  1. ' *** SHARE_EX.BAS - SHARED statement programming example ***
  2. ' This program calls a subprogram, Convert, to convert an
  3. ' input decimal number to its string representation
  4. ' in a specified base. The program uses SHARED to allow the
  5. ' string to be shared by the subprogram and main program.
  6. '
  7. DECLARE SUB Convert (D%, Nb%)
  8. DEFINT A-Z
  9. CLS    ' Clear screen
  10. PRINT "Enter zero or a negative number to quit": PRINT
  11. DO
  12.    INPUT "Decimal number: ", Decimal
  13.    IF Decimal <= 0 THEN EXIT DO
  14.    INPUT "New base: ", Newbase
  15.    N$ = ""
  16.    PRINT Decimal; "base 10 equals ";
  17.    DO WHILE Decimal > 0
  18.       CALL Convert(Decimal, Newbase)
  19.       Decimal = Decimal \ Newbase
  20.    LOOP
  21.    PRINT N$; " base"; Newbase
  22.    PRINT
  23. LOOP
  24.  
  25. SUB Convert (D, Nb) STATIC
  26. SHARED N$
  27.    ' Take the remainder to find the value of the current
  28.    ' digit.
  29.    R = D MOD Nb
  30.    ' If the digit is less than ten, return a digit (0...9).
  31.    ' Otherwise, return a letter (A...Z).
  32.    IF R < 10 THEN Digit$ = CHR$(R + 48) ELSE Digit$ = CHR$(R + 55)
  33.    N$ = RIGHT$(Digit$, 1) + N$
  34. END SUB
  35.  
  36.