Carga de ComboBox y Calculo de Edad en Visual Basic
CONSIGNA
Crear un formulario que permita utilizando ComboBox ingresar la fecha de nacimiento
(aaaa/m/dd) y a partir de ello calcular la edad exacta de la persona.
Observaciones:
- Se debe identificar si el año es bisiesto.
- Se debe cargar automáticamente el combo días de acuerdo al mes.
INTERFAZ
CÓDIGO FUENTE
Private Sub Combo1_Click()
Combo2.Enabled = True
Combo2.Clear
Combo3.Clear
For i = 1 To 12
Combo2.AddItem i
Next i
End Sub
Private Sub Combo2_Click()
Combo3.Clear
If Val(Combo2.Text) = 2 Then
......If (Val(Combo1.Text) Mod 4 = 0 And Val(Combo1.Text) Mod 100 <> 0 Or Val(Combo1.Text)
......Mod 400 = 0) Then
......dias = 29
......Else
......dias = 28
......End If
Else
......If Val(combo2text) Mod 2 = 0 Then
......dias = 30
......Else
......dias = 31
......End If
End If
Combo3.Enabled = True
For i = 1 To dias
......Combo3.AddItem i
Next i
End Sub
Private Sub Combo3_Click()
nacimiento = Combo3.Text + "/" + Combo2.Text + "/" + Combo1.Text
Text1.Text = Int(DateDiff("m", nacimiento, Date) / 12)
'datediff("formato",fecha1,fecha2)devuelve la diferencia entre dos fechas'
'formatos m: meses, d: días, yyyy: años'
'En este caso para conseguir la edad exacta se hace la diferencia en meses'
'al resultado se divide por 12'
'por último se utiliza int(variable) para redondear el resultado'
End Sub
Private Sub Form_Load()
LIMPIAR_Click
End Sub
Private Sub LIMPIAR_Click()
Combo1.Clear
Combo2.Clear
Combo3.Clear
Combo2.Enabled = False
Combo3.Enabled = False
Text1.Text = ""
For i = 2015 To 1915 Step -1
......Combo1.AddItem i
Next i
End Sub
Private Sub SALIR_Click()
Unload Me
End Sub
Congratulations @mauricioeb83! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Congratulations @mauricioeb83! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
thank you very much