Function Valida_CMC7(Entrada As String) As Boolean
Dim Campo1 As String, Campo2 As String, Campo3 As String
Campo1 = Mid(Entrada, 1, 7)
Campo2 = Mid(Entrada, 9, 10)
Campo3 = Mid(Entrada, 20, 10)
Valida_CMC7 = True
If DacBarras(Campo1) <> Mid(Entrada, 19, 1) Then
Valida_CMC7 = False
Else
If DacBarras(Campo2) <> Mid(Entrada, 8, 1) Then
Valida_CMC7 = False
Else
If DacBarras(Campo3) <> Mid(Entrada, 30, 1) Then
Valida_CMC7 = False
End If
End If
End If
End Function
Public Function DacBarras(strNumero As String) As String
Dim strDac As String, soma As Integer, Resto As Integer
Dim i As Integer, Soma1 As Integer
Dim MatResto
MatResto = Array("", 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)
For i = 1 To Len(strNumero)
soma = Val(Mid(strNumero, (Len(strNumero) + 1) - i, 1))
soma = soma * MatResto(i)
strDac = strDac & soma
Next
soma = 0
For i = 1 To Len(strDac)
Soma1 = Mid(strDac, i, 1)
soma = soma + Soma1
Next
Resto = soma Mod 10
strDac = 10 - Resto
If strDac = 10 Then strDac = 0
DacBarras = strDac
End Function
Marcelo Amaral