Autor Tema: Verificación de CUIT  (Leído 2132 veces)

0 Usuarios y 1 Visitante están viendo este tema.

softmania

  • Bytes
  • *
  • Mensajes: 35
  • Reputación: +4/-0
    • Ver Perfil
Verificación de CUIT
« en: Octubre 25, 2013, 10:37:27 pm »
Esta función permite verificar si el CUIT ingresado es correcto

Código: (VB) [Seleccionar]
  Public Function VerificacionCuit(ByVal sValor As String) As Boolean
        Dim sValorNeto As String
        Dim iSuma As Integer
        Dim iResto As Integer
        Dim iVerificador As Integer
        Dim iVerificadorCadena As Integer
        Dim iValorMaTrizConst() As Integer = {5, 4, 3, 2, 7, 6, 5, 4, 3, 2}
        Dim iCont As Integer
        'by softmania
        'Quitamos los caracteres que no usaremos
        sValorNeto = sValor.Replace("-", "").ToString
        'sValorNeto = Valor.Replace("/", "").ToString

        Try
            'verificamos que sean 11 dígitos
            If sValorNeto.Length <> 11 Then Return False : Exit Function
            'separamos el dígito verificador del resto de los números
            iVerificadorCadena = CInt(sValorNeto.Substring(10, 1).ToString)
            'separamos todos los números del dígito verficador
            sValorNeto = sValorNeto.Substring(0, 10).ToString

            For iCont = 0 To 9
                'aquí se suman las multiplicaciones de cada dígito por cada número contenido en la matríz
                'ejemplo 20-28175331-1
                'sería
                '  2   0   2    8   1    7    5    3   3   1
                'X
                '  5   4   3    2   7    6    5    4   3   2
                '-------------------------------------------
                ' 10 + 0 + 6 + 16 + 7 + 42 + 25 + 12 + 9 + 2 =  129

                iSuma = iSuma + (CInt(sValorNeto.Substring(iCont, 1)) * iValorMaTrizConst(iCont))

            Next
            ' Obtenermos el resto de la suma dividida 11
            iResto = iSuma Mod 11


            'Según el resto obtenido calculamos el dígito verificador
            If iResto = 0 Then
                iVerificador = 0
            ElseIf iResto = 1 Then
                iVerificador = 9
            Else
                iVerificador = 11 - iResto
            End If

            'comparamos el dígito verificador obtenido con el dígito de verificación ingresado
            'establecemos si la función devuelve false o true según corresponda
            If iVerificador = iVerificadorCadena Then
                Return True

            Else
                Return False

            End If

        Catch ex As Exception
            Return False
        End Try

    End Function
Solo se que no se nada!!! ;) By Sócrates