por Layer » Lun Jun 06, 2005 6:04 am
Ola. Prueba con estas dos funciones(copia el código, pegalo a un módulo e invocala desde los métodos keydown y keypress):
funciones en el módulo:
OPTION BASE 1(necesario para la funcion)
Public Function ValidarFecha(Fecha As String) As Boolean ' PONER
Dim dia As Byte, mes As Byte, anno As Byte
Dim DiaMes()
DiaMes = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
' otra forma de declarar la matriz
'Dim diames(1 To 12) As Byte
'diames(1)=31:diames(2)=28......diames(12)=31
ValidarFecha = True
If Len(Fecha) < 8 Then
ValidarFecha = False
Else
dia = Left(Fecha, 2)
mes = Mid(Fecha, 4, 2)
anno = Right(Fecha, 2)
If mes > 12 Then 'se valida si el mes es > que 12
ValidarFecha = False
Else
If (anno Mod 4) = 0 Then
DiaMes(2) = 29
Else
DiaMes(2) = 28
End If
If dia > DiaMes(mes) Then
ValidarFecha = False
End If
End If
End If
End Function
' validar la máscara de fecha para q acepte numeros y la barra
Public Function ValidarMascFecha(codigo As Integer, TEXTO As TextBox) As Integer 'usar en el keypress
If codigo <> 8 Then
If (TEXTO.SelStart <> 2 And TEXTO.SelStart <> 5) Then
TEXTO.SelLength = 1
ValidarMascFecha = ValidarNumeroEntero(codigo)
ElseIf codigo = 47 Then ' código ascii del car. /
ValidarMascFecha = codigo
Else
ValidarMascFecha = 0
End If
Else
ValidarMascFecha = codigo
End If
End Function
método keydown:
if keycode=13 then
if validarfecha(txtComoSea.Text)=False
instrucciones
else
instrucciones
end if
método keypress:
keyascii=validarmascfecha(keyascii,txtComoSea)
Espero que te sea de utilidad
Preguntar para aprender, aprender para ayudar