wie und mit welchem Ereignis kann ich am besten prüfen, ob die Eingabe in eine Textbox eine gültige Uhrzeit im Format 12:45
ist. Möglich soll sein 00:00 bis 23:59 ?
Danke für jede Antwort!
wie und mit welchem Ereignis kann ich am besten prüfen, ob die Eingabe in eine Textbox eine gültige Uhrzeit im Format 12:45
ist. Möglich soll sein 00:00 bis 23:59 ?
Danke für jede Antwort!
Jetzt habe ich gerade etwas gebastelt :-) nun schicke ich es doch noch.
Hier wird geprüft welche fehlerhafte Eingabe erfolgt ist:
End Sub
Code eingefügt mit Syntaxhighlighter 1.16
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim sStr As Integer
Dim txt As String
Dim MyTime As Variant
sStr = 0
txt = Me.TextBox1.Value
If Len(txt) < 3 Or Len(txt) > 5 Then
MsgBox ("Falsches Zeitformat")
Me.TextBox1.SetFocus
Exit Sub
End If
If Mid(txt, 1, 1) = ":" Then
MsgBox ("Keine Stunden angegeben")
Me.TextBox1.SetFocus
Exit Sub
End If
For i = 1 To Len(txt)
If Mid(txt, i, 1) = ":" Then
sStr = sStr + 1
End If
Next i
If sStr > 1 Then
MsgBox ("Zuviele Doppelpunkte")
Me.TextBox1.SetFocus
Exit Sub
ElseIf sStr = 0 Then
MsgBox ("Kein Doppelpunkt für Zeitformat erkennbar")
Me.TextBox1.SetFocus
Exit Sub
End If
End If
If Left(txt, InStr(1, txt, ":") - 1) > 23 Then
MsgBox ("Stundenformat falsch")
Me.TextBox1.SetFocus
Exit Sub
End If
If Len(Right(txt, Len(txt) - InStr(1, txt, ":"))) = 0 Or Right(txt, Len(txt) - InStr(1, txt, ":")) > 59 Then
MsgBox ("Minutenformat falsch")
Me.TextBox1.SetFocus
Exit Sub
End If
MyTime = Format(txt, "hh:mm")
Gruss Rainer
Man muss exact arbeiten :-))
Mit IsDate gebe ich dir recht, aber die Länge kannst du zum Beispiel in einer Inputbox nicht vorgeben.
Den Code kannst du universel verwenden.
Gruss RAiner