QB / QB64 Discussion Forum      Other Subforums, Links and Downloads

Respond to this messageReturn to Index
Original Message
  • This one handles all LONGs except &H80000000.
    • (Login MCalkins)
      Moderator
      Posted Oct 9, 2005 9:54 PM

      DEFINT A-Z: DIM t$, v AS LONG, iv, iv2, r$, or$, or2$, ab AS LONG
      CLS
      DO
       COLOR 7, 0: PRINT : PRINT : PRINT "Just press ENTER to quit."
       PRINT "Entering "; &H80000000; "(&H80000000) will cause an overflow error."
       LINE INPUT "Please enter a signed long integer: "; t$
       IF LTRIM$(t$) = "" THEN EXIT DO
       ON ERROR GOTO errhan: v = VAL(t$): ab = ABS(v): ON ERROR GOTO 0
       GOSUB findit: COLOR , 1: PRINT r$: COLOR , 0: PRINT v
      LOOP
      SYSTEM

      findit:                 'inputs v, outputs r$
       IF v THEN
        IF v AND &H80000000 THEN r$ = "negative" ELSE r$ = "positive"
        iv = (ab \ 1000000000) MOD 1000
        IF iv > 0 THEN GOSUB doit: r$ = r$ + or$ + " billion"
        iv = (ab \ 1000000) MOD 1000
        IF iv > 0 THEN GOSUB doit: r$ = r$ + or$ + " million"
        iv = (ab \ 1000) MOD 1000
        IF iv > 0 THEN GOSUB doit: r$ = r$ + or$ + " thousand"
        iv = ab MOD 1000
        IF iv > 0 THEN GOSUB doit: r$ = r$ + or$
       ELSE
        r$ = "zero"
       END IF
       enb = v MOD 4
      RETURN

      doit:                    'inputs iv, outputs or$
       iv2 = (iv \ 100) MOD 10
       IF iv2 > 0 THEN GOSUB onesp: or$ = " " + or2$ + " hundred" ELSE or$ = ""
       iv = iv MOD 100: iv2 = iv \ 10
       IF iv2 > 1 THEN
        SELECT CASE iv2
        CASE 2: or2$ = "twenty"
        CASE 3: or2$ = "thirty"
        CASE 4: or2$ = "fourty"
        CASE 5: or2$ = "fifty"
        CASE 6: or2$ = "sixty"
        CASE 7: or2$ = "seventy"
        CASE 8: or2$ = "eighty"
        CASE 9: or2$ = "ninety"
        END SELECT
        or$ = or$ + " " + or2$
       END IF
       iv2 = iv
       IF (iv2 >= 10) AND (iv2 <= 19) THEN
        SELECT CASE iv2
        CASE 10: or2$ = "ten"
        CASE 11: or2$ = "eleven"
        CASE 12: or2$ = "twelve"
        CASE 13: or2$ = "thirteen"
        CASE 14: or2$ = "fourteen"
        CASE 15: or2$ = "fifteen"
        CASE 16: or2$ = "sixteen"
        CASE 17: or2$ = "seventeen"
        CASE 18: or2$ = "eighteen"
        CASE 19: or2$ = "nineteen"
        END SELECT
        or$ = or$ + " " + or2$
       ELSE
        iv2 = iv2 MOD 10
        IF iv2 > 0 THEN GOSUB onesp: or$ = or$ + " " + or2$
       END IF
      RETURN

      onesp:                  'inputs iv2, outputs or2$
       SELECT CASE iv2
       CASE 1: or2$ = "one"
       CASE 2: or2$ = "two"
       CASE 3: or2$ = "three"
       CASE 4: or2$ = "four"
       CASE 5: or2$ = "five"
       CASE 6: or2$ = "six"
       CASE 7: or2$ = "seven"
       CASE 8: or2$ = "eight"
       CASE 9: or2$ = "nine"
       END SELECT
      RETURN

      errhan:
       COLOR 15: PRINT "ERROR number: "; : v = ERR
      RESUME NEXT
    Login Status
  • You are not logged in
    • Login
      Password
       

      Optional
      Provides additional benefits such as notifications, signatures, and user authentication.


      Create Account
    Your Name
    Message Title
    Message Text
    Options
          


     Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement