Version 3A - Int Speed 3A.vbp

Code changes

This project shows the simple solution to the problems introduced by using DoEvents. Code has been added in each button's Click event to disable all command buttons except for the "End" button.

Disable buttons

This routine disables ALL command buttons except the "End" button.

Private Sub DisableBtn()

cmdVariant.Enabled = False
cmdShort.Enabled = False
cmdLong.Enabled = False
cmdRunALL3.Enabled = False

End Sub

Enable buttons

This routine enables ALL command buttons, and also sets the focus to the "End" button.

Private Sub EnableBtn()

cmdVariant.Enabled = True
cmdShort.Enabled = True
cmdLong.Enabled = True
cmdRunALL3.Enabled = True

cmdStop.SetFocus

End Sub

Modified loop routine

here the changes to call the two new routines are highlighted:

Private Sub cmdLong_Click()

Dim llCounter1 As Long
Dim llCounter2 As Long
Dim llAccum As Long
Dim ldStart As Date
Dim ldStop As Date
Dim lsMsg As String

'Disable all looping Click events
Call DisableBtn


ldStart = Now()
Print
Print "Long Integers:"
Print ldStart

For llCounter1 = 1 To 200
llAccum = 0
DoEvents
If llCounter1 Mod 10 = 0 Then Print ".";
For llCounter2 = 1 To 32000
llAccum = llAccum + 1
Next
Next

Call DispEnd(ldStart, ldStop)

'Enable all looping Click events
Call EnableBtn


End Sub

Alternate solution

The fancier way to solve the problem is to assume that you WANT to allow the executing code to be interrupted. Version 3B has additional code to clean up the display of the information on the form.