sábado, 1 de octubre de 2011

Validar cedula de identidad excel con VS 6.0

Usted debe crear un formulario a su gusto, luego usted insertara el siguiente codigo realizado en VS 6.0:

Private Sub CheckBox1_Click()
If CheckBox1.Value = False Then
    TextBox1.Enabled = False
Else
    TextBox1.Enabled = True
End If
   
End Sub

Private Sub CheckBox2_Click()
If CheckBox2.Value = False Then
    TextBox2.Enabled = False
Else
TextBox2.Enabled = True
End If
End Sub
Private Sub CheckBox3_Click()
If CheckBox3.Value = False Then
    TextBox3.Enabled = False
Else
 TextBox3.Enabled = True
 End If
End Sub


Private Sub CheckBox4_Click()

End Sub

Private Sub CommandButton1_Click()
Sheets("hoja1").Select
Range("A3").Select

Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop

ActiveCell = TextBox1.Value
ActiveCell.Offset(0, 1).Select
ActiveCell = TextBox2.Value
ActiveCell.Offset(0, 1).Select
ActiveCell = TextBox3.Value
ActiveCell.Offset(0, 1).Select


If OptionButton1.Value = True Then
ActiveCell = "soltero"
Else
    If OptionButton2.Value = True Then
    ActiveCell = "casado"
    Else
        If OptionButton3.Value = True Then
        ActiveCell = "Union Libre"
        End If
    End If
End If

ActiveCell.Offset(0, 1).Select
If OptionButton5.Value = True Then
ActiveCell = "Estudiante"
Else
ActiveCell = "Vago"
End If
ActiveCell.Offset(0, 1).Select

End Sub

Private Sub CommandButton2_Click()
' esta accion limpia los objetos que se ha ingresado
TextBox1.Value = Empty
TextBox3.Value = Empty

OptionButton1.Value = False
OptionButton2.Value = False
OptionButton3.Value = False
OptionButton4.Value = False
OptionButton5.Value = False
CheckBox1.Value = False
CheckBox2.Value = False
CheckBox3.Value = False


End Sub

Private Sub CommandButton3_Click()
Unload UserForm1
End Sub

Private Sub CommandButton4_Click()
Dim a As Double
a = TextBox2.Text
If a > 9999999999# Then
    MsgBox ("Cedula fuera del rango (mayor a 10 digitos)")
    CommandButton5.Enabled = False
    Else
        If a < 999999999 Then
            MsgBox ("Cedula fuera del rango (menor a 10 digitos)")
            CommandButton5.Enabled = False
    End If
End If

If a >= 1000000000 And a <= 9999999999# Then
MsgBox ("rango correcto")
CommandButton5.Enabled = True
End If

End Sub


Private Sub CommandButton5_Click()
Dim i, dec_prox As Integer
Dim aux As Double
Dim cifra As Integer
Dim val_imp As Integer
Dim val_par, val_total As Integer
Dim dig_ver As Integer

For i = 1 To 9
    If (i Mod 2) = 0 Then
    cifra = Val(Mid(TextBox2.Text, i, 1))
    val_par = val_par + cifra
    Else
    cifra = Val(Mid(TextBox2.Text, i, 1)) * 2
    val_imp = val_imp + IIf(cifra < 9, cifra, cifra - 9)
    End If
   
Next

Total = val_par + val_imp

For i = 1 To 9
aux = (Total + i) Mod 10
 If aux = 0 Then
    dec_prox = Total + i
    Exit For
 Else
    dec_prox = Total
 End If
Next

dig_ver = dec_prox - Total
'MsgBox (dec_prox)
'MsgBox (Total)
'MsgBox (Val(Mid(TextBox2.Text, 10, 1)))

If dig_ver = Val(Mid(TextBox2.Text, 10, 1)) Then
    MsgBox ("cedula correcta, adios")
Else
    MsgBox ("cedula incorrecta")
End If



End Sub


Private Sub Frame2_Click()

End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label2_Click()

End Sub

Private Sub Label3_Click()

End Sub



Private Sub Label6_Click()

End Sub

Private Sub TextBox1_Change()

End Sub

Private Sub TextBox2_Change()

End Sub

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If (KeyAscii < 48) Or (KeyAscii > 57) Then
KeyAscii = 0
MsgBox "Solo se aceptan números", vbOKOnly + Exclamation, "Atencion"
End If
End Sub

Private Sub TextBox4_Change()

End Sub

Private Sub UserForm_Click()

End Sub

Ya se que debe ser tedioso este asunto pero asi debe ir la parte de programacion. Listo entonces



Felipe Ochoa E.

No hay comentarios: