How do you use a progress bar for functions that take a while to do there thing, i.e. one that goes throught multiple recordsets, extracting data, etc, etc?
I understand how to use a ProgessBar in Loops but not generally in something like the above.
Printable View
How do you use a progress bar for functions that take a while to do there thing, i.e. one that goes throught multiple recordsets, extracting data, etc, etc?
I understand how to use a ProgessBar in Loops but not generally in something like the above.
Hope this works. Put a CommandButton, CommonDialog, Label and ProgressBar into a Form
VB Code:
Private Sub Command1_Click() Dim Source As String Dim Dest As String Dim Data As String Dim TransferRate As Integer CommonDialog1.CancelError = True CommonDialog1.Filter = "All Files|*.*" CommonDialog1.ShowOpen If Err <> 32755 Then Source = CommonDialog1.filename Dest = Source & " - Copy 2" Open Source For Binary As #1 Open Dest For Binary As #2 ProgressBar1.Max = FileLen(Source) TransferRate = 1024 Do Until LOF(1) = Loc(1) Or EOF(1) Data = "" If LOF(1) - Loc(1) < ChunkSize Then Data = String(LOF(1) - Loc(1), 0) Else Data = String(ChunkSize, 0) End If Get #1, , Data Put #2, , Data Label1.Caption = Loc(1) & " bytes out of " & LOF(1) & " transfered" If ProgressBar1.Value + TransferRate > FileLen(Source) Then Exit Do ProgressBar1.Value = ProgressBar1.Value + TransferRate Loop End If End Sub
you can track the progress of an operation only if you know before you get started how many steps it involves (that would be the .Max property of your progress bar) and only if you gain control into your application when each step is done (e.g. the long operation would generate events or something). other than that, you may be able to estimate how long the operation is going to take, and have a timer to modify the .Value of your progress bar every second or so... and you will probably get the micosoft's progress bar effect, when the fill factor either jumps from 35% to 100%, or gets stuck to 99% completed for 50% of the entire time...
Thanks guys.
You've got me thinking along the right track now radum - I'll give that a go and let you know how I get on in this forum thread.
Cheers.