This still misbehaves. You click the start, and it starts. You click the stop or the form's client area and the start button depresses.
Having done that, clicking the stop then functions. (?)
Code:
Public Class Form1
Dim T As Integer
Dim A As Integer
Public Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Start1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start1.Click
A = 1
T = 300
Do While A = 1
ProcessRB(1): If A = 0 Then Exit Do
ProcessRB(2): If A = 0 Then Exit Do
ProcessRB(3): If A = 0 Then Exit Do
ProcessRB(4): If A = 0 Then Exit Do
ProcessRB(5)
Loop
End Sub
Public Sub ProcessRB(ControlNum As Integer)
Dim c As Control
c = Me.Controls("RB" & ControlNum)
c.BackColor = System.Drawing.Color.LightGreen
Me.Refresh()
If A = 0 Then Exit Sub
wait(T)
If A = 0 Then Exit Sub
c.BackColor = System.Drawing.Color.Red
Me.Refresh()
End Sub
Public Sub wait(ByVal dblMilliseconds As Double)
Dim dblStart As Double
Dim dblEnd As Double
Dim dblTickCount As Double
dblTickCount = GetTickCount()
dblStart = GetTickCount()
dblEnd = GetTickCount + dblMilliseconds
Do
dblTickCount = GetTickCount()
System.Windows.Forms.Application.DoEvents()
If a = 0 Then Exit Do
Loop Until dblTickCount > dblEnd Or dblTickCount < dblStart
End Sub
Private Sub Stop1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click
A = 0
RB1.BackColor = System.Drawing.Color.Blue
RB2.BackColor = System.Drawing.Color.Blue
RB3.BackColor = System.Drawing.Color.Blue
RB4.BackColor = System.Drawing.Color.Blue
RB5.BackColor = System.Drawing.Color.Blue
End Sub
End Class