Private Sub te_cuil_Leave(sender As Object, e As EventArgs) Handles Txt_Cuil.Leave
If Txt_Cuil.Text <> "" Then
Dim a(11) As Integer, n As Single
'cargo en la matriz de izquierda a derecha los numeros correspondientes
'al cuit ingresado en text1.text sin los guiones suponiendo
'que el cuit o cuil sea = 30-50052945-4
a(1) = CInt(Mid(Txt_Cuil.Text, 1, 1)) '= 3
a(2) = CInt(Mid(Txt_Cuil.Text, 2, 1)) '= 0
a(3) = CInt(Mid(Txt_Cuil.Text, 4, 1)) '= 5
a(4) = CInt(Mid(Txt_Cuil.Text, 5, 1)) '= 0
a(5) = CInt(Mid(Txt_Cuil.Text, 6, 1)) '= 0
a(6) = CInt(Mid(Txt_Cuil.Text, 7, 1)) '= 5
a(7) = CInt(Mid(Txt_Cuil.Text, 8, 1)) '= 2
a(8) = CInt(Mid(Txt_Cuil.Text, 9, 1)) '= 9
a(9) = CInt(Mid(Txt_Cuil.Text, 10, 1)) '= 4
a(10) = CInt(Mid(Txt_Cuil.Text, 11, 1)) '= 5
a(11) = CInt(Mid(Txt_Cuil.Text, 13, 1)) '= 4
'calculo el digito verificador
n = (a(1) * 6) + (a(2) * 7) + (a(3) * 8) + (a(4) * 9) + (a(5) * 4) + (a(6) * 5) + (a(7) * 6) + (a(8) * 7) + (a(9) * 8) + (a(10) * 9)
n = ((n / 11) - Int(n / 11)) * 11
'el valor de n tiene que ser = a a(11) es decir 4 o el cuit esta mal
If n = a(11) Then
Else
XtraMessageBox.Show("El cuil es incorrecto", "Error al ingresar el Cuil", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Else
XtraMessageBox.Show("Debe Ingresar el Cuil", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
Txt_Cuil.Focus()
End If
End Sub
---------------------------------------------------------------------------------------------------------
Public Shared Function NumeroCuit(ByVal numero As String) As Boolean
Dim iSuma As Integer = 0
Dim bValidado As Boolean = False
numero = numero.Replace("-", "")
If IsNumeric(numero) Then
If CLng(numero) <= 0 Then Return False
If numero.Length <> 11 Then
Return False
Else
Dim inicio As Integer = CInt(numero.Substring(0, 2))
If inicio <> 20 And inicio <> 23 And inicio <> 24 And inicio <> 27 _
And inicio <> 30 And inicio <> 33 Then Return False
iSuma += CInt(numero.Substring(0, 1)) * 5
iSuma += CInt(numero.Substring(1, 1)) * 4
iSuma += CInt(numero.Substring(2, 1)) * 3
iSuma += CInt(numero.Substring(3, 1)) * 2
iSuma += CInt(numero.Substring(4, 1)) * 7
iSuma += CInt(numero.Substring(5, 1)) * 6
iSuma += CInt(numero.Substring(6, 1)) * 5
iSuma += CInt(numero.Substring(7, 1)) * 4
iSuma += CInt(numero.Substring(8, 1)) * 3
iSuma += CInt(numero.Substring(9, 1)) * 2
iSuma += CInt(numero.Substring(10, 1)) * 1
End If
If Math.Round(iSuma / 11, 0) = (iSuma / 11) Then
bValidado = True
End If
End If
Return bValidado
End Function