while Schleife abbrechen geht nicht
25.07.2013 17:11:10
Dirk
ich versuche eine While-Schleife mit ESC abzubrechen, aber irgendwie klappt das nicht so, wie ich mir das vorstelle. Ich habe in diversen Foren unterschiedliche Lösungen gefunden und mehrere ausprobiert. Ohne Inhalt klappt es, aber mit Inhalt funktioniert es leider nicht.
Hier mal der Code:
Option Explicit
Private b As Boolean
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then b = False
End Sub
Private Sub start_program()
On Error GoTo ErrorHandler
Dim idn As String
Dim i As Integer
Dim ic As Integer
Dim c As Integer
Dim Z As Integer
Dim tst As String
Dim volt As Double
Dim curr As Double
Dim INP As Double
Dim Vstepa As Double
Dim Tstepa As Double
Dim NoVal As Double
Dim slist As String
Dim voca As Double
Dim numdat As String
Dim Sh1 As Worksheet
Set Sh1 = ActiveSheet
INP = 1
voca = tbLoadBank11.Value ' Startwert Spannung
Vstepa = tbLoadBank13.Value ' Step der Spannung
Tstepa = tbLoadBank14.Value ' Zeit pro Step
NoVal = tbLoadBank15.Value ' Messpunkte pro Step
b = True
i = 0
Z = 0
Sh1.Cells(1, 1) = "Timestamp"
For ic = 11 To 18
If UserForm1.Controls("ch" & ic).Value " " Then
Sh1.Cells(1, ic - 9) = UserForm1.Controls("name" & ic).Value + " [" + UserForm1. _
Controls("label" & ic) + "]"
Else
Sh1.Cells(1, ic - 9) = ""
End If
Next
Do While (voca > 0 Or b = True)
DoEvents
i = i + 1
Z = Z + 1
Sh1.Cells(i + 1, 1) = Now()
Application.Wait (Now() + TimeValue(Format(Tstepa / 86400, "hh:mm:ss")))
For c = 1 To numdat
UserForm1.Controls("display" & c + 10).Value = Sh1.Cells(i + 1, c + 1)
Next
If Z = NoVal Then
voca = voca - Vstepa
Z = 0
End If
Loop
MsgBox "Stop loop!"
Exit Sub
ErrorHandler:
MsgBox ("Something went wrong! Start failed!")
End Sub
Ich habe die Maschinendaten gelöscht, die im Code waren, da es ein Datenlesegerät anspricht.
Des Weiteren habe ich, wie hier im Forum beschrieben, aus der While-Schleife eine Do While-Schleife gemacht.
Es liegt irgendwie an der Application.Wait.
Wenn ich ESC drücke, liesst die Maschine sofort den Wert aus, es scheint so als wird Application.Wait beendet. Nur fängt das Ganze direkt wieder von vorne an, da die Do While -Schleife nicht beendet wird.
Nachdem voca > 0 erreicht wird, wird die Schleife beendet.
Hat jemand eine Idee?
Ich bin über jede Hilfe sehr dankbar !!!
Viele Grüße und DANKE
Dirk