|
|
|
|
|
Dicas
|
|
Visual Basic (Operações Matemáticas)
|
|
|
Título da Dica: Validar contas do Banco do Brasil (Atualizado)
|
|
|
|
Postada em 8/5/2007 por ¨PCNATIVO
'Valida contas do Banco do Brasil Public Function IsValidCC(sConta As String) As Boolean On Error GoTo errHandler: Dim x As Long, s As String, iResult As Integer, sTotal As String For x = 1 To Len(sConta) - 1 If IsNumeric(Mid(sConta, x, 1)) Then s = s & Mid(sConta, x, 1) Next If Len(s) > 11 Then Exit Function For x = 0 To Len(Mid(s, 1, 11)) - 1 Select Case 9 - x Case 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 iResult = iResult + (Mid(Mid(s, 1, 11), _ Len(Mid(s, 1, 11)) - x, 1) * (9 - x)) Case Else iResult = iResult + (Mid(Mid(s, 1, 11), _ Len(Mid(s, 1, 11)) - x, 1) * (9)) End Select Next sTotal = Int(iResult / 11): sTotal = Int(sTotal * 11): sTotal = Int(iResult - sTotal) If sTotal = 10 Then sTotal = "X" If Right(sConta, 1) = sTotal Then IsValidCC = True Exit Function errHandler: IsValidCC = False End Function
|
|
|
|
|