Start und Stopzeit prüfen

valeripf

Erfahrenes Mitglied
Kann mir Helfen

und zwar Ich Habe 2 Textboxen 1) F_Start1 2)F_Stop2
in dieser TextBoxen Ist Zeit Angabe Stunden: Minuten:Sekunden

Frage: Ich will Überprüfen der F_Start1 Textbox soll Kleiner sein als F_Stop1 Textbox
Zumbeispiel F_Start1 ist 1:05:35 F_Stop1 ist 2:08:52

Wenn nicht der Fall dann MsgBox ("der Stopzeit muss Großer sein als Startzeit")
MsgBox ("der Startzeit muss Kleiner als Stopzeit")

die start und stopzeit sehen so aus
Visual Basic:
Private Sub F_Start1_Change()
    If F_Start1.TextLength < 1 Or F_Start1.TextLength > 1000 Then F_Start1.BackColor = RGB(255, 0, 0) Else F_Start1.BackColor = RGB(255, 255, 255)
    If BoEnter = True Then Exit Sub
    If Len(F_Start1) = 2 Then
        If InStr(F_Start1, ":") = 0 And BoEnter = False Then F_Start1 = F_Start1 & ":"
    ElseIf Len(F_Start1) = 5 Then
        If Len(F_Start1) - Len(Application.Substitute(F_Start1, ":", "")) < 2 Then
            TextF_Start1 = F_Start1 & ":"
        End If
    End If
    If F_Start1.Text = "" Then
        FStop1.Enabled = False
        Else
        F_Stop1.Enabled = True
    End If
End Sub
Private Sub F_Start1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Select Case KeyAscii
        Case Asc("0") To Asc("9")
        Case Asc(":")
            If Len(F_Start1) = 0 Then
                KeyAscii = 0
            Else
                If Len(F_Start1) - Len(Application.Substitute(F_Start1, ":", "")) = 2 Then
                    KeyAscii = 0
                ElseIf Len(F_Start1) > 1 Then
                    If Mid(F_Start1, Len(F_Start1), 1) = ":" Then KeyAscii = 0
                Else
                    KeyAscii = Asc(":")
                End If
            End If
        Case Else
            KeyAscii = 0
    End Select
End Sub
Private Sub F_Start1_AfterUpdate()
    BoEnter = True
    If Right(F_Start1, 1) = ":" Then F_Start1 = Mid(F_Start1, 1, Len(F_Start1) - 1)
    If Len(F_Start1) - Len(Application.Substitute(F_Start1, ":", "")) = 1 Then
        F_Start1 = F_Start1 & ":" & "00"
    End If
    If IsDate(F_Start1.Text) Then
        If Format(CDate(F_Start1.Value), "hh:mm:ss") <> F_Start1 Then
            MsgBox "Das Datum wurde übersetzt"
        End If
        F_Start1 = Format(CDate(F_Start1.Value), "hh:mm:ss")
    Else
        F_Start1 = ""
    End If
    BoEnter = False
End Sub
Private Sub F_Stop1_Change()
    If F_Stop1.TextLength < 1 Or F_Stop1.TextLength > 1000 Then F_Stop1.BackColor = RGB(255, 0, 0) Else F_Stop1.BackColor = RGB(255, 255, 255)
    If BoEnter = True Then Exit Sub
    If Len(F_Stop1) = 2 Then
        If InStr(F_Stop1, ":") = 0 And BoEnter = False Then F_Stop1 = F_Stop1 & ":"
    ElseIf Len(F_Stop1) = 5 Then
        If Len(F_Stop1) - Len(Application.Substitute(F_Stop1, ":", "")) < 2 Then
            TextF_Stop1 = F_Stop1 & ":"
        End If
    End If
End Sub

DANKE VORAUS
 
Zuletzt bearbeitet:
Du kannst mit TimeValue(arg) den String parsen. Das Ergebnis kannst du mit Vergleichsoperatoren vergleichen.

Edit Beispiel:
Visual Basic:
If TimeValue("1:05:35") > TimeValue("2:08:52") Then
  MsgBox ("Die Stopzeit muss größer sein als die Startzeit.")
End If
 
Zuletzt bearbeitet:
Zurück