Results 1 to 4 of 4

Thread: How do you use a progress bar for...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    New Zealand
    Posts
    78

    Question How do you use a progress bar for...

    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.

  2. #2
    Addicted Member ripple214's Avatar
    Join Date
    Nov 2002
    Location
    In Front of My Computer
    Posts
    141
    Hope this works. Put a CommandButton, CommonDialog, Label and ProgressBar into a Form
    VB Code:
    1. Private Sub Command1_Click()    
    2. Dim Source As String    
    3. Dim Dest As String    
    4. Dim Data As String    
    5. Dim TransferRate As Integer        
    6. CommonDialog1.CancelError = True    
    7. CommonDialog1.Filter = "All Files|*.*"    CommonDialog1.ShowOpen        
    8. If Err <> 32755 Then            
    9. Source = CommonDialog1.filename        
    10. Dest = Source & " - Copy 2"        
    11. Open Source For Binary As #1        
    12. Open Dest For Binary As #2                
    13. ProgressBar1.Max = FileLen(Source)      
    14. TransferRate = 1024                
    15. Do Until LOF(1) = Loc(1) Or EOF(1)          
    16. Data = ""            
    17. If LOF(1) - Loc(1) < ChunkSize Then                
    18. Data = String(LOF(1) - Loc(1), 0)            
    19. Else                
    20. Data = String(ChunkSize, 0)            
    21. End If            Get #1, , Data            
    22. Put #2, , Data                        
    23. Label1.Caption = Loc(1) & " bytes out of " & LOF(1) & " transfered"            
    24. If ProgressBar1.Value + TransferRate > FileLen(Source) Then Exit Do            
    25. ProgressBar1.Value = ProgressBar1.Value + TransferRate                  
    26. Loop            
    27. End If    
    28. End Sub
    [vbcode]
    If SymptomsPersist Then Goto VBForum
    [/vbcode]
    This is our world now...the world of the electron and the switch, the beauty of the baud.We make use of a service already existing without paying for what could be dirt cheep if it wasn't run by profiteering gluttons, and you call us criminals. We explore...and you call us criminals. We exist without skin color, without nationality, without religious bias...and you call us criminals. You build atomic bombs, wage wars, murder, cheat, and lie to us and try to make us believe it is for our own good, yet we're the criminals. Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for. I am a hacker and this is my manifesto.You may stop this individual, but you can't stop us all...after all, we're all alike."

    +++The Mentor+++

  3. #3
    Fanatic Member
    Join Date
    Feb 2003
    Location
    Los Angeles, CA
    Posts
    681
    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...
    there are 2 reasons why i leave my work unfinished:
    (1) i'm getting old.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    New Zealand
    Posts
    78
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width