You are on page 1of 5

Public Sub ValidaDocumento(Pcedula As String) Dim Suma As Double Dim Residuo As Double Dim Natural, Juridica, Publica As Boolean

Dim NumProvincias As Byte NumProvincias = 22 Natural = False Juridica = False Publica = False If Len(Trim(Pcedula)) >= 10 Then c1 = Mid(Pcedula, 1, 1) c2 = Mid(Pcedula, 2, 1) c3 = Mid(Pcedula, 3, 1) c4 = Mid(Pcedula, 4, 1) c5 = Mid(Pcedula, 5, 1) c6 = Mid(Pcedula, 6, 1) c7 = Mid(Pcedula, 7, 1) c8 = Mid(Pcedula, 8, 1) c9 = Mid(Pcedula, 9, 1) C10 = Mid(Pcedula, 10, 1) Select Case c3 ' Para verificar si es persona Natural,Juridica o Empresa del sector pblico Case Is < 6 Natural = True Case Is = 6 Publica = True Case Is = 9 Juridica = True End Select If Natural = True Then If val(Mid(Pcedula, 1, 2)) > 0 And val(Mid(Pcedula, 1, 2)) <= NumPro vincias Then p1 = c1 * 2 p2 = c2 * 1 p3 = c3 * 2 p4 = c4 * 1 p5 = c5 * 2 p6 = c6 * 1 p7 = c7 * 2 p8 = c8 * 1 p9 = c9 * 2 P10 = C10 * 1 If p1 >= 10 Then p1 = p1 - 9 End If If p2 >= 10 Then p2 = p2 - 9 End If If p3 >= 10 Then p3 = p3 - 9 End If If p4 >= 10 Then p4 = p4 - 9 End If If p5 >= 10 Then p5 = p5 - 9 End If

If p6 >= 10 Then p6 = p6 - 9 End If If p7 >= 10 Then p7 = p7 - 9 End If If p8 >= 10 Then p8 = p8 - 9 End If If p9 >= 10 Then p9 = p9 - 9 End If If P10 >= 10 Then P10 = P10 - 9 End If Suma = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + P10 Residuo = Suma Mod 10 If Len(Trim(Pcedula)) = 10 Then If Residuo = 0 Then 'MsgBox "La cedula es valida.", vbInformation, "Aviso." Todocorrecto = "S" Me.txtcampos(6).Text = Me.txtcampos(6).Text Else MsgBox "La cedula no es valida.", vbInformation, "Aviso ." Todocorrecto = "N" If Me.txtcampos(6).Enabled = True Then Me.txtcampos(6).SetFocus End If End If ElseIf Len(Trim(Pcedula)) > 10 Then If Residuo = 0 Then If val(Mid(Pcedula, 11, 3)) = 1 And Len(Mid(Pcedula, 11 , 3)) = 3 Then If Len(Trim(Mid(Pcedula, 11, 3))) = Len(Mid(Pcedula, 11, 3)) Then 'MsgBox "El ruc es valido.", vbInformation, "Avi so." Todocorrecto = "S" Else MsgBox "Nmero de Ruc correspondiente a Persona Na tural es incorrecta, por favor verificar", vbInformation, "Aviso." Todocorrecto = "N" If Me.txtcampos(6).Enabled = True Then Me.txtcampos(6).SetFocus End If End If Else MsgBox "Nmero de Ruc correspondiente a Persona Natura l es incorrecta, por favor verificar", vbInformation, "Aviso." Todocorrecto = "N" If Me.txtcampos(6).Enabled = True Then Me.txtcampos(6).SetFocus End If End If Else 'If val(Mid(Pcedula, 11, 3)) = 1 And Len(Mid(Pcedula, 11 , 3)) = 3 And val(Mid(Pcedula, 1, 2)) >= 1 And val(Mid(Pcedula, 1, 2)) <= NumPro

vincias Then 'OJO SE AUMENTA ESTA LNEA If Residuo = 0 Then If Len(Trim(Mid(Pcedula, 11, 3))) = Len(Mid(Pcedula, 11, 3)) Then 'MsgBox "El ruc es valido.", vbInformation, "Avi so." Todocorrecto = "S" Else MsgBox "Nmero de Ruc correspondiente a Persona Na tural es incorrecta, por favor verificar", vbInformation, "Aviso." Todocorrecto = "N" If Me.txtcampos(6).Enabled = True Then Me.txtcampos(6).SetFocus End If End If Else MsgBox "Nmero de Ruc correspondiente a Persona Natura l es incorrecta, por favor verificar", vbInformation, "Aviso." Todocorrecto = "N" If Me.txtcampos(6).Enabled = True Then Me.txtcampos(6).SetFocus End If End If End If End If ' Else Todocorrecto = "N" MsgBox "Ruc de Persona Natural incorrecto, por favor verificar l os digitos correspondientes a la Provincia", vbInformation, "Aviso." If Me.txtcampos(6).Enabled = True Then Me.txtcampos(6).SetFocus End If End If End If ' natural If Juridica = True Then If val(Mid(Pcedula, 1, 2)) > 0 And val(Mid(Pcedula, 1, 2)) <= NumPro vincias Then If Len(Trim(Pcedula)) = 13 Then p1 = c1 * 4 p2 = c2 * 3 p3 = c3 * 2 p4 = c4 * 7 p5 = c5 * 6 p6 = c6 * 5 p7 = c7 * 4 p8 = c8 * 3 p9 = c9 * 2 Suma = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 ValDivision = Int(Suma / 11) ValMultiplicacion = ValDivision * 11 VALRESTA = Suma - ValMultiplicacion ' RESIDUO If VALRESTA = 0 Then digitoverificador = 0

Else digitoverificador = 11 - VALRESTA End If If val(digitoverificador) = val(C10) And val(Mid(Pcedula, 11 , 3)) = 1 Then Todocorrecto = "S" Else Todocorrecto = "N" MsgBox "Nmero de Ruc correspondiente a Persona Jurdica es incorrecta, por favor verificar", vbInformation, "Aviso." If Me.txtcampos(6).Enabled = True Then Me.txtcampos(6).SetFocus End If End If End If Else Todocorrecto = "N" MsgBox "Ruc de Persona Jurdica incorrecto, por favor verificar lo s digitos correspondientes a la Provincia", vbInformation, "Aviso." If Me.txtcampos(6).Enabled = True Then Me.txtcampos(6).SetFocus End If End If End If If Publica = True Then If val(Mid(Pcedula, 1, 2)) > 0 And val(Mid(Pcedula, 1, 2)) <= NumPro vincias Then If Len(Trim(Pcedula)) = 13 Then p1 = c1 * 3 p2 = c2 * 2 p3 = c3 * 7 p4 = c4 * 6 p5 = c5 * 5 p6 = c6 * 4 p7 = c7 * 3 p8 = c8 * 2 Suma = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 ValDivision = Int(Suma / 11) ValMultiplicacion = ValDivision * 11 VALRESTA = Suma - ValMultiplicacion digitoverificador = 11 - VALRESTA If val(c9) = val(digitoverificador) And val(Mid(Pcedula, 10, 4)) > 0 And val(Mid(Pcedula, 11, 3)) = 1 Or VALRESTA = 0 Then Todocorrecto = "S" Else MsgBox "Nmero de Ruc correspondiente a Empresas del Secto r Pblico es incorrecta, por favor verificar", vbInformation, "Aviso." Todocorrecto = "N" If Me.txtcampos(6).Enabled = True Then Me.txtcampos(6).SetFocus End If End If End If Else Todocorrecto = "N" MsgBox "Ruc de Empresas del Sector Pblico incorrecto, por favor v erificar los digitos correspondientes a la Provincia", vbInformation, "Aviso." If Me.txtcampos(6).Enabled = True Then

Me.txtcampos(6).SetFocus End If End If End If Else MsgBox "Numero de Documento no vlido.", vbInformation, "Aviso." Todocorrecto = "N" If txtcampos(6).Enabled = True Then Me.txtcampos(6).SetFocus End If End If End Sub

You might also like