Function fFormatCC(strCC As String) As String
'Returns: formatted Credit Card Number
'Useage: ?fFormatCC("6011000050002215")
'Returned Value: DCxxxxxxxxxx2215
Dim intLength As Integer 'String Length
Dim intXcount As Integer 'Number of x's to use
Dim strFormattedCC As String 'Formatted String
Dim strCardType As String 'Card Type
intLength = Len(strCC)
intXcount = intLength - 6 'CC Length - (CardType + Last 4 digits)
strCardType = Left(strCC, 1)
Select Case strCardType
Case 3
If intLength <> 12 Then
GoTo CC_ERROR
Else
strFormattedCC = "TP"
End If
Case 4
If intLength <> 16 Then
GoTo CC_ERROR
Else
strFormattedCC = "VI"
End If
Case 5
If intLength <> 16 Then
GoTo CC_ERROR
Else
strFormattedCC = "MC"
End If
Case 6
If intLength <> 16 Then
GoTo CC_ERROR
Else
strFormattedCC = "DC"
End If
Case Else
GoTo CC_ERROR
End Select
'Add the x's
Do Until intXcount = 0
strFormattedCC = strFormattedCC & "x"
intXcount = intXcount - 1
Loop
'Add the last 4 digits
strFormattedCC = strFormattedCC & Right(strCC, 4)
'Return the formatted string
fFormatCC = strFormattedCC
Exit Function
CC_ERROR:
MsgBox "Invalid Card Number, exiting routine.", vbCritical, "Invalid Card #"
End Function