Display number while counting

sohailcdc

Registered User.
Local time
Yesterday, 19:26
Joined
Sep 25, 2012
Messages
55
Hi there
I am just trying to learn during my free time
Anyways, I am trying to learn display counter
I try to google but unable to find anything what I am looking for

Below is my code, which works, but only problem is result shows once counting is done - whereas I am interested in upon changing "i" Text20 should also change its value


Private Sub Command22_Click()
Dim i As Double
Dim maxnumber As Double
maxnumber = 100000
For i = 1 To maxnumber
Me.Text20.Value = i
Next i

End Sub
 
You only see the last number because the 100000 loops in the Sub would be completed in less than the time it takes for the display to refresh.
 
Also to keep the application from "freezing up" you want to add DoEvents into the loop...

IMPORTANT NOTE:
DoEvents takes some time to actually do and will slow down your code significantly
I usually do something like
Code:
If Int ( Mycounter/100) = MyCounter/100 then 
    Me.Somecontrol = Mycounter
    doevents
endif

offcourse you can vary the 100 to a fitting amount for your purpose, usually updating per 1 is a bad idea due to performance issues.
 

Users who are viewing this thread

Back
Top Bottom