BCX Console Demonstration Program s110.bas

 ' ------------------------------------------ 
 ' Check validity of a credit card number 
 ' Based on public domain code written 
 ' by Frank Cox, September 1, 1991.) 
 ' ------------------------------------------ 
 ' --- Modified for BCX by Kevin Diggins --- 
 ' ------------------------------------------ 
 
 DIM Card$
 
 INPUT "Input Charge Card Number: ", Card$
 
 IF LEN(Card$) = 0 THEN END
 
 IF CCValid(Card$) THEN
   PRINT "Valid"
 ELSE
   PRINT "Invalid"
 END IF
 
 FUNCTION CCValid(TheCard$)
   LOCAL Tmp$
   LOCAL c, m, Temp, CheckSum
 
   Tmp$ = REMOVE$(TheCard$, CHR$(32))     ' remove spaces from the data 
   FOR c = (LEN(Tmp$) - 1) TO 1 STEP -1   ' compute the checksum 
     IF m = 2 THEN
       m = 1
     ELSE
       m = 2
     END IF
     Temp = VAL(MID$(Tmp$, c, 1)) * m
     CheckSum = CheckSum + Temp
     IF Temp > 9 THEN CheckSum = CheckSum - 9
   NEXT
 
   IF MOD((CheckSum + VAL(RIGHT$(Tmp$, 1))), 10) = 0 THEN
     FUNCTION = -1
   ELSE
     FUNCTION = 0
   END IF
 
 END FUNCTION

Result:


 Input Charge Card Number: 0000
 Valid