Click to See Complete Forum and Search --> : Fastest way to give an update...
Phobic
Dec 7th, 1999, 08:43 AM
Ok, I have this program, and one of it's processes deals with for statements, and sometimes these statements can be looping for quite awhile. It's always nice to let the user know how far along the progress is, but the fact of the matter is that showing the progress slows down the progress of the loop... right now I'm using the Print Method in a picturebox, AutoRedraw is off, FontTransparent is False so that I don't have to clear the picturebox with new text. I find that in a standard loop of mine, same amount of loops for every test without DoEvents used, it takes and extra three seconds with progress reports than normal. That's a lot, considering that this test is a small test. What's the fastest way to give the user a progress report with the most minimal delay in the loop?
sushant
Dec 7th, 1999, 10:33 AM
You can have a disabled timer control. Before the starting of the loop, enable the timer which shows the time in seconds in a label control. After the loop, disable the timer.
MartinLiss
Dec 7th, 1999, 10:32 PM
Why not use the ProgressBar control that is part of the Microsoft Windows Common Controls 5.0 or 6.0?
------------------
Marty
Phobic
Dec 8th, 1999, 03:45 AM
yes, my code is as fast as it can get for what it does, I used the progress bar already and it's much faster just because it updates in intervals, not every interval. I was just wondering what the fastest possible way for giving an update is, I guess the progress bar is it.
Aaron Young
Dec 8th, 1999, 11:41 AM
Have you tried optimizing your code?
The following progress bar adds an average of 2 seconds to a process..
Private Sub DoProgress(ByVal iValue As Integer, ByVal iMax As Integer)
With Picture1
If iValue = 0 Then
.CurrentX = 0
.Cls
End If
Picture1.Line (.CurrentX, 0)-((.ScaleWidth / iMax) * iValue, .ScaleHeight), , BF
End With
End Sub
Example..
Private Sub Command1_Click()
Dim iNum As Integer
Dim tTimer As Single
Picture1.ForeColor = vbBlue
For iNum = 0 To 10000
DoProgress iNum, 10000
'Perform my Process..
tTimer = Timer
While (Timer - tTimer) < 0.001
Wend
'End of my Process
Next
End Sub
Private Sub DoProgress(ByVal iValue As Integer, ByVal iMax As Integer)
With Picture1
If iValue = 0 Then
.CurrentX = 0
.Cls
End If
Picture1.Line (.CurrentX, 0)-((.ScaleWidth / iMax) * iValue, .ScaleHeight), , BF
End With
End Sub
This only draws the part fo the Progressbar required, not the whole thing as the box upto that point is already blue.
Another Option would be not to call the Progress bar on every interation of your Loop, calling it every other iteration would halve the time it took, eg.
Private Sub Command1_Click()
Dim iNum As Integer
Dim tTimer As Single
Picture1.ForeColor = vbBlue
For iNum = 0 To 10000
If iNum Mod 2 Then DoProgress iNum, 10000
'Perform my Process..
tTimer = Timer
While (Timer - tTimer) < 0.001
Wend
'End of my Process
Next
End Sub
Private Sub DoProgress(ByVal iValue As Integer, ByVal iMax As Integer)
With Picture1
If iValue = 0 Then
.CurrentX = 0
.Cls
End If
Picture1.Line (.CurrentX, 0)-((.ScaleWidth / iMax) * iValue, .ScaleHeight), , BF
End With
End Sub
In the end, it's not really a case of how much slower your progress bar makes the process, it's how it affects the Percieved Time, does the Process seem to go quicker with the Progressbar?
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net
[This message has been edited by Aaron Young (edited 12-08-1999).]
Gerald
Dec 8th, 1999, 11:58 AM
Are you updating your progress display with every iteration of your For loop? If this is the case, you may want to put an If statement around your progress display code that only allows the code to execute on every 10th, 100th or whatever iteration of the loop. This will cut down on the number of machine code instructions that must be processed to update the display. The amount of time required to test the If condition is miniscule when compared to the amount of time required to update the screen display.
The following code will only execute the Debug.Print statement 10 times.
For n = 1 To 1000
If n Mod 100 = 0 Then
Debug.Print n
End If
Next
Gerald M.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.