Korrektur-Timer - Frage
- VB.NET
- .NET (FX) 4.0
Sie verwenden einen veralteten Browser (%browser%) mit Sicherheitsschwachstellen und können nicht alle Funktionen dieser Webseite nutzen.
Hier erfahren Sie, wie einfach Sie Ihren Browser aktualisieren können.
Hier erfahren Sie, wie einfach Sie Ihren Browser aktualisieren können.
Es gibt 39 Antworten in diesem Thema. Der letzte Beitrag () ist von RodFromGermany.
-
-
Danke für Deine Antwort.
RodFromGermany schrieb:
Und ne MessageBox in der Timer.Tick-Prozedur ist ein NoGo.
Wie kann man das Lösen?
Gruß Andreas -
-
Also das Problem bei einer MessageBox im Timer ist einfach folgendes: Wenn du irgendeinen kleinen Code-Fetzen falsch programmiert hast, oder der User einfach immer wieder die gleiche, oder eine falsche eingabe macht, welche du dann in
Timer.Tick
abfragst, und eventuell eine MessageBox ausgibst, dann ist die Kacke -je nach Timer-Intervall- erst richtig am dampfen, weil der User dann mit MessageBoxen zugespamt wird. -
-
-
-
-
Ich habe das ganze so geändert und in eine Sub geschoben.
Ist das so besser?
Spoiler anzeigen VB.NET-Quellcode
- Private Sub Zünd_Timer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Zünd_timer.Tick
- Label_Time.Text = stopwatch.Elapsed.ToString.Remove(10)
- timer_vergleichen()
- End Sub
- Sub timer_vergleichen()
- Dim LT As DateTime = DateTime.Parse(Label_Time.Text)
- Dim t1 As DateTime = DateTime.Parse(TextBox1.Text)
- Dim t2 As DateTime = DateTime.Parse(TextBox2.Text)
- Dim t3 As DateTime = DateTime.Parse(TextBox3.Text)
- Dim t4 As DateTime = DateTime.Parse(TextBox4.Text)
- Dim t5 As DateTime = DateTime.Parse(TextBox5.Text)
- Dim t6 As DateTime = DateTime.Parse(TextBox6.Text)
- Dim t7 As DateTime = DateTime.Parse(TextBox7.Text)
- Dim t8 As DateTime = DateTime.Parse(TextBox8.Text)
- Dim t9 As DateTime = DateTime.Parse(TextBox9.Text)
- Dim t10 As DateTime = DateTime.Parse(TextBox10.Text)
- Dim t11 As DateTime = DateTime.Parse(TextBox11.Text)
- Dim t12 As DateTime = DateTime.Parse(TextBox12.Text)
- Dim t13 As DateTime = DateTime.Parse(TextBox13.Text)
- Dim t14 As DateTime = DateTime.Parse(TextBox14.Text)
- Dim t15 As DateTime = DateTime.Parse(TextBox15.Text)
- Dim t16 As DateTime = DateTime.Parse(TextBox16.Text)
- Dim t17 As DateTime = DateTime.Parse(TextBox17.Text)
- Dim t18 As DateTime = DateTime.Parse(TextBox18.Text)
- Dim t19 As DateTime = DateTime.Parse(TextBox19.Text)
- Dim t20 As DateTime = DateTime.Parse(TextBox20.Text)
- Dim t21 As DateTime = DateTime.Parse(TextBox21.Text)
- Dim t22 As DateTime = DateTime.Parse(TextBox22.Text)
- Dim t23 As DateTime = DateTime.Parse(TextBox23.Text)
- Dim t24 As DateTime = DateTime.Parse(TextBox24.Text)
- Dim t25 As DateTime = DateTime.Parse(TextBox25.Text)
- Dim t26 As DateTime = DateTime.Parse(TextBox26.Text)
- Dim t27 As DateTime = DateTime.Parse(TextBox27.Text)
- Dim t28 As DateTime = DateTime.Parse(TextBox28.Text)
- Dim t29 As DateTime = DateTime.Parse(TextBox29.Text)
- Dim t30 As DateTime = DateTime.Parse(TextBox30.Text)
- Dim t31 As DateTime = DateTime.Parse(TextBox31.Text)
- Dim t32 As DateTime = DateTime.Parse(TextBox32.Text)
- Dim t33 As DateTime = DateTime.Parse(TextBox33.Text)
- Dim t34 As DateTime = DateTime.Parse(TextBox34.Text)
- Dim t35 As DateTime = DateTime.Parse(TextBox35.Text)
- Dim t36 As DateTime = DateTime.Parse(TextBox36.Text)
- Dim t37 As DateTime = DateTime.Parse(TextBox37.Text)
- Dim t38 As DateTime = DateTime.Parse(TextBox38.Text)
- Dim t39 As DateTime = DateTime.Parse(TextBox39.Text)
- Dim t40 As DateTime = DateTime.Parse(TextBox40.Text)
- If LT >= t1 Then
- TextBox1.BackColor = Color.Red
- Else
- TextBox1.BackColor = Color.White
- End If
- If LT >= t2 Then
- TextBox2.BackColor = Color.Red
- Else
- TextBox2.BackColor = Color.White
- End If
- If LT >= t3 Then
- TextBox3.BackColor = Color.Red
- Else
- TextBox3.BackColor = Color.White
- End If
- If LT >= t4 Then
- TextBox4.BackColor = Color.Red
- Else
- TextBox4.BackColor = Color.White
- End If
- If LT >= t5 Then
- TextBox5.BackColor = Color.Red
- Else
- TextBox5.BackColor = Color.White
- End If
- If LT >= t6 Then
- TextBox6.BackColor = Color.Red
- Else
- TextBox6.BackColor = Color.White
- End If
- If LT >= t7 Then
- TextBox7.BackColor = Color.Red
- Else
- TextBox7.BackColor = Color.White
- End If
- If LT >= t8 Then
- TextBox8.BackColor = Color.Red
- Else
- TextBox8.BackColor = Color.White
- End If
- If LT >= t9 Then
- TextBox9.BackColor = Color.Red
- Else
- TextBox9.BackColor = Color.White
- End If
- If LT >= t10 Then
- TextBox10.BackColor = Color.Red
- Else
- TextBox10.BackColor = Color.White
- End If
- If LT >= t11 Then
- TextBox11.BackColor = Color.Red
- Else
- TextBox11.BackColor = Color.White
- End If
- If LT >= t12 Then
- TextBox12.BackColor = Color.Red
- Else
- TextBox12.BackColor = Color.White
- End If
- If LT >= t13 Then
- TextBox13.BackColor = Color.Red
- Else
- TextBox13.BackColor = Color.White
- End If
- If LT >= t14 Then
- TextBox14.BackColor = Color.Red
- Else
- TextBox14.BackColor = Color.White
- End If
- If LT >= t15 Then
- TextBox15.BackColor = Color.Red
- Else
- TextBox15.BackColor = Color.White
- End If
- If LT >= t16 Then
- TextBox16.BackColor = Color.Red
- Else
- TextBox16.BackColor = Color.White
- End If
- If LT >= t17 Then
- TextBox17.BackColor = Color.Red
- Else
- TextBox17.BackColor = Color.White
- End If
- If LT >= t18 Then
- TextBox18.BackColor = Color.Red
- Else
- TextBox18.BackColor = Color.White
- End If
- If LT >= t19 Then
- TextBox19.BackColor = Color.Red
- Else
- TextBox19.BackColor = Color.White
- End If
- If LT >= t20 Then
- TextBox20.BackColor = Color.Red
- Else
- TextBox20.BackColor = Color.White
- End If
- If LT >= t21 Then
- TextBox21.BackColor = Color.Red
- Else
- TextBox21.BackColor = Color.White
- End If
- If LT >= t22 Then
- TextBox22.BackColor = Color.Red
- Else
- TextBox22.BackColor = Color.White
- End If
- If LT >= t23 Then
- TextBox23.BackColor = Color.Red
- Else
- TextBox23.BackColor = Color.White
- End If
- If LT >= t24 Then
- TextBox24.BackColor = Color.Red
- Else
- TextBox24.BackColor = Color.White
- End If
- If LT >= t25 Then
- TextBox25.BackColor = Color.Red
- Else
- TextBox25.BackColor = Color.White
- End If
- If LT >= t26 Then
- TextBox26.BackColor = Color.Red
- Else
- TextBox26.BackColor = Color.White
- End If
- If LT >= t27 Then
- TextBox27.BackColor = Color.Red
- Else
- TextBox27.BackColor = Color.White
- End If
- If LT >= t28 Then
- TextBox28.BackColor = Color.Red
- Else
- TextBox28.BackColor = Color.White
- End If
- If LT >= t29 Then
- TextBox29.BackColor = Color.Red
- Else
- TextBox29.BackColor = Color.White
- End If
- If LT >= t30 Then
- TextBox30.BackColor = Color.Red
- Else
- TextBox30.BackColor = Color.White
- End If
- If LT >= t31 Then
- TextBox31.BackColor = Color.Red
- Else
- TextBox31.BackColor = Color.White
- End If
- If LT >= t32 Then
- TextBox32.BackColor = Color.Red
- Else
- TextBox32.BackColor = Color.White
- End If
- If LT >= t33 Then
- TextBox33.BackColor = Color.Red
- Else
- TextBox33.BackColor = Color.White
- End If
- If LT >= t34 Then
- TextBox34.BackColor = Color.Red
- Else
- TextBox34.BackColor = Color.White
- End If
- If LT >= t35 Then
- TextBox35.BackColor = Color.Red
- Else
- TextBox35.BackColor = Color.White
- End If
- If LT >= t36 Then
- TextBox36.BackColor = Color.Red
- Else
- TextBox36.BackColor = Color.White
- End If
- If LT >= t37 Then
- TextBox37.BackColor = Color.Red
- Else
- TextBox37.BackColor = Color.White
- End If
- If LT >= t38 Then
- TextBox38.BackColor = Color.Red
- Else
- TextBox38.BackColor = Color.White
- End If
- If LT >= t39 Then
- TextBox39.BackColor = Color.Red
- Else
- TextBox39.BackColor = Color.White
- End If
- If LT >= t40 Then
- TextBox40.BackColor = Color.Red
- Else
- TextBox40.BackColor = Color.White
- End If
- End Sub
Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „ErfinderDesRades“ ()
-
Da ist 40 mal dasselbe gecodet - solch kann man mit einer Schleife besser abhandeln:
VB.NET-Quellcode
- Private Sub Zünd_Timer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Zünd_timer.Tick
- Dim time = Stopwatch.Elapsed 'die Zeit merken, nicht das Label
- Label_Time.Text = time.ToString.Remove(10)
- timer_vergleichen(time)
- End Sub
- Sub timer_vergleichen(ByVal time As Date) 'die Zeit übergeben, nicht von irgendwoher holen
- Dim textboxes As TextBox() = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, TextBox7, TextBox8, TextBox9, TextBox10, TextBox11, TextBox12, TextBox13, TextBox14, TextBox15, TextBox16, TextBox17, TextBox18, TextBox19, TextBox20, TextBox21, TextBox22, TextBox23, TextBox24, TextBox25, TextBox26, TextBox27, TextBox28, TextBox29, TextBox30, TextBox31, TextBox32, TextBox33, TextBox34, TextBox35, TextBox36, TextBox37, TextBox38, TextBox39, TextBox40}
- For Each tb In textboxes
- tb.BackColor = If(time >= Date.Parse(tb.Text), Color.Red, Color.White)
- Next
- End Sub
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „ErfinderDesRades“ ()
-
-
ist gut, wenn man typisiert arbeitet, ne?
Dann kommt man drauf, dass man keine Datumse vorliegen hat, sondern Zeitspannen.VB.NET-Quellcode
- Private _Stopwatch As New Stopwatch
- Private Sub Zünd_Timer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Zünd_timer.Tick
- Dim time = _Stopwatch.Elapsed 'die Zeit merken, nicht das Label
- Label_Time.Text = time.ToString.Remove(10)
- timer_vergleichen(time)
- End Sub
- Sub timer_vergleichen(ByVal time As TimeSpan) 'die Zeit übergeben, nicht von irgendwoher holen
- Dim textboxes As TextBox() = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, TextBox7, TextBox8, TextBox9, TextBox10, TextBox11, TextBox12, TextBox13, TextBox14, TextBox15, TextBox16, TextBox17, TextBox18, TextBox19, TextBox20, TextBox21, TextBox22, TextBox23, TextBox24, TextBox25, TextBox26, TextBox27, TextBox28, TextBox29, TextBox30, TextBox31, TextBox32, TextBox33, TextBox34, TextBox35, TextBox36, TextBox37, TextBox38, TextBox39, TextBox40}
- For Each tb In textboxes
- tb.BackColor = If(time >= TimeSpan.Parse(tb.Text), Color.Red, Color.White)
- Next
- End Sub
-
-
hier der Screenshot - ist nur ein Testprogramm für eine spätere Anwendung.
Und jetzt kommt diese Fehlermeldung - 2. ScreenshootDieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Hicki“ ()
-
-
-
es hätte zwar nur sinn, wenn du die Änderungen fändest, die ich vorgenommen habe, aber seis drum
-
Vielen Dank, hast mir sehr geholfen.
Die Änderung habe ich schon gefunden, aber ich habe nicht das String-Format bedacht.
Gruß Andreas
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Hicki“ ()
-
jepp - und das Format ist auch bisserl komisch - weisst du, wie man VisualStudio dazu bringt, die Dokumentation dazu anzuzeigen?
VisualStudio richtig nutzen (Google ist nicht deine Mami) -
Hicki schrieb:
Und wo plaziere ich die MessageBoxen im Code?Console.WriteLine("bla")
, das wird dann im Studio unten im Debug-Tab ausgegeben.Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch
Ein guter .NET-Snippetkonverter (der ist verfügbar).
Programmierfragen über PN / Konversation werden ignoriert!
-
Ähnliche Themen
-
xD Hacker - - Sonstige Problemstellungen
-
7 Benutzer haben hier geschrieben
- Hicki (15)
- ErfinderDesRades (10)
- ichduersie (7)
- RodFromGermany (3)
- Thunderbolt (2)
- ~blaze~ (2)
- Gast (1)