RE:Dato de tiempo(Mejora)
Bueno, más tarde me dí cuenta que lo anteriormente dicho, solo vale para horas del día, y no para tiempos, ya que puede haber 37 min 12 s...Y esto no lo aceptaría lo anterior.
Así que me he puesto a darle vueltas y he sacado este código para alguien que lo necesite:
Private Sub Text_Change()
If Len(Text) = 2 Then
Text = Text + ":"
Text.SelStart = 3
End If
End Sub
Private Sub Text_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode > 47 And KeyCode < 58 Then
If Len(Text) = 5 Then
Text = Text + ":"
Text.SelStart = 6
End If
End If
End Sub
Private Sub Text_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) Then
If KeyAscii <> 8 And KeyAscii <> 9 And KeyAscii <> 13 Then
KeyAscii = 0
End If
End If
End Sub
Private Sub Text_LostFocus()
Dim cadena() As String
cadena() = Split(Text, ":")
tam = UBound(cadena()) + 1
If tam = 2 Then
If Val(cadena(0)) < 0 Or Val(cadena(0)) > 59 Then
MsgBox "Minutos no válidos"
Text.Text = ""
Text.SetFocus
End If
If Val(cadena(1)) < 0 Or Val(cadena(1)) > 59 Then
MsgBox "Segundos no válidos"
Text.Text = ""
Text.SetFocus
End If
End If
If tam = 3 Then
If Val(cadena(1)) < 0 Or Val(cadena(1)) > 59 Then
MsgBox "Minutos no válidos"
Text.Text = ""
Text.SetFocus
End If
If Val(cadena(2)) < 0 Or Val(cadena(2)) > 59 Then
MsgBox "Segundos no válidos"
Text.Text = ""
Text.SetFocus
End If
End If
End Sub
Este ejemplo sirve tanto para horas,minutos y segundos, como para minutos y segundos solamente.
Sigo aceptando sugerencias de mejora. Un saludo.