As i have seen in the firt part of your program, result is showing the time of clicking inbetween Enable timer first(Cmd3) to
Stop Timer(cmd1) button.
In the second part, result is showing the same but here you have done summation of seris of clicking inbetween Enable timer
first(Cmd4) to Stop Timer(cmd2) button.
But i am not getting the result as i want. May be i am not getting the logic as you are thinking.
I think you are cleared what i want. However, i am once again putting my requirement.
I want to measure the time require by a long procedure from first line to last line that may be 1000 lines of codes or few
loop and elseif statement as i have puted a loop in my test program (1 To 1000000). I want to see the time how many seconds are taking by that procedure or other procedure
In my test program command1(First Test) button showing the result as starting and ending time of procedure. Where i can see the difference as 10 seconds in my PC (Pentium 4). And that test has been done without taking the help of timer.
In the Command2(second test) and Command3(third test), i have used timer but result has not got. And i have seen when i cliked on all three button one by one timers controls are pausing when commands are running.
a million count loop will slow down your computer into an almost crawl. If you really want to show the status of a loop in time, use a progress bar. Remember that a user's pc might be slower or faster than your test machine, resulting in a lot of unwanted returned time results.:)
Also use DoEvents(), very useful if you have time consuming, cpu eating code since it will allow Windows to process the Applications messages and thus, your Application/Program will not freeze while the high cpu usage code is running. This will allow the user to continue to interact with your program while the cpu intensive task is running.
BUT unfortunately, there is a tradeoff if you use DoEvents(). That tradeoff is ‘Performance’. The more you call DoEvents() the higher the performance drop since Windows will have to check and use the cpu to process your apps messages/procedures and will take some cpu cycles away from your monster code. Thankfully, there IS a solution to ‘Partially’ offset the performance loss of using DoEvents() while ‘Still’ keeping the application from freezing.
'Under your command button - ...
Private Sub Command5_Click()
Timer1.Enabled = True
prg.Min = 0
prg.Max = 1000000
prg.Value = 0
Dim xLoop As Double
Do While xLoop <= 1000000
If prg.Value >= 1000000 Then
Timer1.Enabled = False
xLoop = xLoop + 1
prg.Value = prg.Value + 1
'Under the timer - ...
Private Sub Timer1_Timer()
lblOnce.Caption = lblOnce.Caption + Timer1.Interval
That should now solve your problem. You are giving the user some 'visible' input by means of the progressbar AND you can time the loop.:)
Sir, i have got another solution for checking execution time of a procedure. This time i have got the solution in fraction without using timer.
Private Sub Command1_Click() 'without timer its successfull
Dim ST As Double
Dim FT As Double
ST = Timer
For a = 1 To 1000000 Step 1
Label1.Caption = Val(Label1.Caption) + 1
FT = Timer
Text1.Text = "Total time required by this procedure is " + Str(FT - ST) + " Seconds"
Your information is valuable for me sir and thanks for being with me for solving this question. Still I am keeping all my hair in original state. It may be happen as you said for my other question :), because i am trying heard for getting solution.