Domino Code Fragment

Code Name*
Luhn credit card algorithm
Date*
04/09/1999
Source (or email address if you prefer)*
lotusnotes@mailcity.com
IP address:.
Description*
Validates a credit card number
Type*
LotusScript
Categories*
User Interface (Notes)
Implementation:
Modify constants
Required Client:
Server:
4.5
Limitations:
Comments:
The field names are pretty self explanatory.
Files/Graphics attachments (if applicable): Code:
Sub Click(Source As Button)
     Dim nCheckSum As Integer
     Dim fDbl As Integer
     Dim strvalidate$
     Dim nCharPos As Integer
     Dim nChar As Integer
     Dim strCC$
     Dim L%
     Dim workspace As New NotesUIWorkspace 'Declare workspace to the current open Notes workspace
     Dim uidoc As NotesUIDocument  'Declare uidoc as a Notes document interface type
     Dim twoLiner As String
     twoLiner = |Input Credit Card Number WITHOUT Spaces or Dashes|
     
     Set uidoc = workspace.CurrentDocument
     
     fDbl = False
     nCheckSum = 0
     strCC = Inputbox (twoliner & Chr$(10) + Chr$(10))
     L% = Len(strCC)                                                           'Length of Credit Card Number          
     If L% = 0 Then Exit Sub
     If (L% <> 13 And L% <> 15 And L% <> 16) Then            ' Check to see if the length of the CC # is valid
          Messagebox("Wrong number of digits, please check the card number and retry." )  
          Exit Sub
     Else          
     End If
     
' if statement here to check for 0 characters
     If strCC$ = "0000000000000"  Or strCC = "000000000000000" Or strCC = "0000000000000000"Then
          Messagebox("Please do not enter all zeros as the credit card number.")
          Exit Sub
     Else          
     End If
     
     
'Read the card number from right to left
     For nCharPos = Len( strCC ) To 1 Step -1
          nChar = Asc( Mid( strCC, nCharPos, 1 ) ) - Asc( "0" )
         
     '     If nChar <> 48 Or nChar <> 49 Or nChar <> 50 Or nChar <> 51 Or  nChar <> 52 Or nChar <> 53 Or nChar <> 54 Or nChar <> 55 Or nChar <> 56  Or nChar <> 57 Then
          If nChar >9 Then
               Messagebox("Invalid character in credit card number")
               Exit Sub
          Else
          End If
         
'Only process if the current character is a digit
          If 0 <= nChar And nChar <= 9 Then
               If ( fDbl ) Then
                    nChar = nChar * 2
                    If 10 <= nChar Then
                         nChar = nChar - 9
                    End If
               End If
               nCheckSum = nCheckSum + nChar
               fdbl = Not fdbl
          End If
     Next
     If nCheckSum Mod 10 <> 0 Then  
          Messagebox("Not a valid credit card number, please press the button again after verifying the number.")    
          Exit Sub              
     Else    
          Call uidoc.FieldSetText("Account" , strCC)
         
          Call checkdate          
     End If
     Exit Sub
End Sub

------ Additional Sub to check date.

Sub checkdate
     
gotodatecheck:
     Dim workspace As New NotesUIWorkspace 'Declare workspace to the current open Notes workspace
     Dim uidoc As NotesUIDocument  'Declare uidoc as a Notes document interface type
     Set uidoc = workspace.CurrentDocument    
     strvalidate = Inputbox("Input Expiration date. I.E. MM/YY or 12/99")
     L1% = Len(strvalidate)
     If L1% < 4 Then
     Else      
          Call uidoc.FieldSetText("Expdate" , strvalidate)
         
               'place date in Expdate field.
' Set item = doc.ReplaceItemValue( "Expdate", strvalidate  )      
         ' uidoc.Expdate = strvalidate
     End If
End Sub