'--------------------------------------------------------
'Function CheckCardNumber (svCardNumber as Variant) As Variant
'
'Purpose:	Checks credit card numbers to determine if number
'		is valid or not. By running the card through the
'		logic below, the end result should be divisble by
'		10.  If it is not, an invalid card was submitted.
'
'		Note:  	This does NOT check the validity of the bank
'		       	number (first 4 digits).  There are databases
'			that can supply valid bank numbers elsewhere.
'
'Expects:	Any credit card number as a variant.
'Returns:	True if card is valid, False if not valid.
'
'Author:	Ron Sparks, Blockbuster Online Services
'		74351.404@compuserve.com
'		BlockTec@aol.com
'
'Last Modification Date:	06/17/96
'--------------------------------------------------------
Function CheckCardNumber (svCardNumber As Variant) As Variant
    Dim wMonth As Integer, wYear As Integer, szExpirationDate
    Dim vFileDate As Variant
    Dim wCheckDigit  As Integer
    Dim wDigitCounter As Integer, wDigits As Integer, wSum As Integer
    Dim wCurrentDigit As Integer, wDigitValue As Integer

    CheckCardNumber = True

    wDigits = Len(svCardNumber)
    wSum = 0
    For wDigitCounter = 1 To wDigits
        wCurrentDigit = wDigits - wDigitCounter + 1
        wDigitValue = Mid(svCardNumber, wCurrentDigit, 1)
        If (Int(wDigitCounter / 2)) = (wDigitCounter / 2) Then
            If (wDigitValue > 4) Then
                wSum = wSum + (2 * wDigitValue - 9)
            Else
                wSum = wSum + (2 * wDigitValue)
            End If
        Else
            wSum = wSum + wDigitValue
        End If
    Next wDigitCounter

    If Not ((Int(wSum / 10)) = wSum / 10) Then
        MsgBox ("Invalid Card Number" & Chr(10) & Chr(13) & svCardNumber)
        CheckCardNumber = False
    End If

End Function


'--------------------------------------------------------
'Function CheckExpirationDate (vExpirationDate As Variant) As Variant
'
'Purpose:	Checks credit card expiration date
'
'Expects:	Any credit card expiration date	without a dash (/) 
'		as a variant in the format myy or mmyy.
'Returns:	True if date is valid, False if not valid.
'
'Author:	Ron Sparks, Blockbuster Online Services
'		74351.404@compuserve.com
'		BlockTec@aol.com
'
'Last Modification Date:	06/17/96
'--------------------------------------------------------
Function CheckExpirationDate (vExpirationDate As Variant) As Variant
    Dim wMonth As Integer, wYear As Integer
    Dim vFileDate As Variant

    CheckExpirationDate = True

    If Len(vExpirationDate) = 3 Then
        vExpirationDate = "0" & vExpirationDate
    End If

    If Len(vExpirationDate) < 3 Then
        MsgBox ("Invalid Expiration Date" & Chr(10) & Chr(13) & vExpirationDate)
        CheckExpirationDate = False
    End If

    If Left(vExpirationDate, 2) > 12 Or Left(vExpirationDate, 2) < 1 Then
        MsgBox ("Invalid Month in Expiration Date" & Chr(10) & Chr(13) & vExpirationDate)
        CheckExpirationDate = False
    End If

    If (Right$(vExpirationDate, 2) & Left$(vExpirationDate, 2)) < Format$(Date, "yymm") Then
        MsgBox ("Expired Card" & Chr(10) & Chr(13) & vExpirationDate)
        CheckExpirationDate = False
    End If

End Function
