• Viernes 17 de Mayo de 2024, 01:47

Autor Tema:  Re: validación de RUT o Cedula de Identidad  (Leído 2824 veces)

jorge2002

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Re: validación de RUT o Cedula de Identidad
« en: Miércoles 24 de Abril de 2002, 09:26 »
0
necesito saber como puedo validar rut o cedula de identidad por ej: 13.548.752-3

SEBA

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
validación de RUT o Cedula de Identidad
« Respuesta #1 en: Lunes 19 de Agosto de 2002, 18:48 »
0
Sub ValidaRUT(ByRef txt As TextBox)
   
    Dim Codigo As String
    'Dim Flag As Boolean
    Dim Rut As String
    Dim rut_integer, i, factor, suma, digito, digitostr

    Flag = True
    If txt.Text <> "" Then
        Flag = False
        If ((InStr(1, txt, "-") <> 0) And (InStr(1, txt, "-") = (Len(Trim(txt)) - 1))) Then
           'largo y exitencia del guión
           
            If Len(txt.Text) > 3 Then
                If IsNumeric(Left(txt.Text, Len(txt.Text) - 2)) Then
                    Rut = CLng(Left(txt.Text, Len(txt.Text) - 2))
                    Codigo = Right(txt.Text, 1)
   
                    If Codigo = "K" Then Codigo = "k"
                    suma = 0
                    rut_integer = CLng(Rut)
                    factor = 2
                    For i = Len(Rut) To 0 Step -1
                        If factor > 7 Then factor = 2
                        suma = suma + (rut_integer Mod 10) * factor
                        rut_integer = rut_integer  10
                        factor = factor + 1
                    Next
                    digito = 11 - (suma Mod 11)
                    If digito = 10 Then digitostr = "k"
                    If digito = 11 Then digitostr = "0"
                    If digito < 10 Then digitostr = Right(CStr(digito), 1)
                    If digitostr = Codigo Then Flag = True
                End If
            End If
        End If
        If Flag = False Then
            MsgBox "ADVERTENCIA: EL RUT INGRESADO NO ES VALIDO!!", vbOKOnly, "ADVERTENCIA"
            txt.Text = ""
            txt.SetFocus
        End If
    End If
   
End Sub