can anyone please give me some sample code on how progress
bars work as im trying to learn how they work
:)
many thanx
johnny
Printable View
can anyone please give me some sample code on how progress
bars work as im trying to learn how they work
:)
many thanx
johnny
In order for you show the progress of something you have to calculate it. Progressbar has 3 main properties that you would have to worry about: Min, Max and Value.
These 3 properies are needed for you in order to show the progress status. So, let's say you have a loop from 1 to 25000, which we will show the status of.
As you can see all I'm calculating is a percentage, i.e. (Counter / Maximum) * 100Code:Private Sub Command1_Click()
Dim i As Integer
With ProgressBar1
.Min = 0 'These values are default
.Max = 100 'but I'm using them, so you'll know what they are for
For i = 1 To 25000
.Value = (i / 25000) * 100
Next
End With
End Sub
Of course, you can use another example like this:
With the first example it is a lot more generic, that means no matter how many times the loop executes, the percentage will be recalculated accordinglyCode:Private Sub Command1_Click()
With ProgressBar1
.Min = 0
.Max = 25000
Do Until .Value = .Max
.Value = .Value + 1
Loop
End With
End Sub
Edited by Serge on 02-23-2000 at 05:18 PM
Johnny, here's a nifty trick for using a progress bar to chart the progress when looping through a recordset. That is usually what I use them for. Here you use the recordset properties to create the Min, Max, and Value properties, like Serge showed you above.
The above example is for an ADO recordset. With DAO the structure would be the same, only the syntax of the recordset properties is a little different.Code:With ProgressBar1
.Value = 0
.Visible = True
.Max = rsMyRecordset.RecordCount
End With
If rsMyRecordset.EOF = False And rsMyRec.BOF = False Then
rsMyRecordset.MoveFirst
Do Until rsMyRecordset.EOF
ProgressBar1.Value = rsMyRecordset.AbsolutePosition + 1
'insert whatever you want the loop to do here
rsMyRecordset.MoveNext
Loop
End Sub
With ProgressBar1
.Value = ProgressBar1.Max
.Visible = False
.Value = 0
End With