Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
Posted: Tue Mar 04, 2008 10:06 am Post subject:
A suggestion to the above code, use Option Explicit and define all your variables, it's better practice and you will not have that option in other languages if and when you move on.
Code:
Option Explicit
Private TickEnable As Boolean
Private TickCount As Long
Private Sub Form_Load()
TickEnable = False ' Default TickEnable To False
TickCount = 0 ' Clear TickCount At Start
End Sub
Private Sub Command1_Click()
TickEnable = True ' Enable TickEnable
Call TickLoop ' Call Loop Function
End Sub
Private Sub Command2_Click()
TickEnable = False ' Disable TickEnable
End Sub
Private Sub TickLoop()
Do While TickEnable = True ' Loop While Enabled
TickCount = TickCount + 1 ' Increase Count By One
Text1.Text = TickCount ' Display Current Count
DoEvents ' Prevent Freezing With Do Loops
Loop
End Sub
If you want to test this, add 1 textbox and two buttons to a form. _________________
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum