Results 1 to 23 of 23

Thread: Delay Progress Bar

  1. #1

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287

    Delay Progress Bar

    Hey,
    I'm using a progress bar to show what's up with the process of adding files into a ListView. Even if the user adds lots of files, the process is still very quick, and I would like the user to be able to actually see the procesing percentage. I there a simple way to delay the loop?

  2. #2

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Delay Progress Bar

    If its that fast then I would think it would be better to provide the speed vs making them wait.

    If you dont really need a progressbar then perhaps show a message somewhere like in a statusbar or such stating process complete or ???
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287

    Re: Delay Progress Bar

    Quote Originally Posted by RhinoBull
    Can you show us how you actually do it?
    Code:
    frmLoading.lblTitle.Caption = "Loading Files..."
    frmLoading.ProgressBar.Max = Data.Files.Count
    frmLoading.ProgressBar.Value = 0
    frmMain.MousePointer = 11
    frmLoading.MousePointer = 11
    frmLoading.Show '1, Me
    frmMain.Enabled = False
    For i = 1 To Data.Files.Count
        Call AddFiles(Data.Files(i), listFiles.ListItems.Count + 1)
        frmLoading.ProgressBar.Value = i
        frmLoading.lblFiles.Caption = i & " Of " & Data.Files.Count
        frmLoading.lblPercent.Caption = (i / Data.Files.Count) * 100 & "%"
    Next i
    frmMain.Enabled = True
    Unload frmLoading
    frmMain.MousePointer = 0
    frmLoading.MousePointer = 0

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Delay Progress Bar

    I would also vote for speed vs delays however you may use Sleep api inside the loop:
    Code:
    Option Explicit
    
    Private Declare Function SleepEx Lib "kernel32" _
        (ByVal dwMilliseconds As Long, ByVal bAlertable As Long) As Long
    
    
    For i = 1 To Data.Files.Count
        Call AddFiles(Data.Files(i), listFiles.ListItems.Count + 1)
        frmLoading.ProgressBar.Value = i
        frmLoading.lblFiles.Caption = i & " Of " & Data.Files.Count
        frmLoading.lblPercent.Caption = (i / Data.Files.Count) * 100 & "%"
    
        SleepEx 200, False 'change number to whatever you wish - just kim that it's in milliseconds
    
    Next i

  6. #6

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287

    Re: Delay Progress Bar

    Quote Originally Posted by RobDog888
    If its that fast then I would think it would be better to provide the speed vs making them wait.
    What do you mean? Like a Count down until the process is done? it will be so fast the user will not be able to see it, maybe only a blink of the form (load and unload)

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Delay Progress Bar

    Quote Originally Posted by Stiletto
    What do you mean? Like a Count down until the process is done? it will be so fast the user will not be able to see it, maybe only a blink of the form (load and unload)
    The point is if it takes so little time then you don't need to show progress - changing cursor to hourglass can be more than enough.

  8. #8

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287

    Re: Delay Progress Bar

    The Sleep API doesnt do much - it freezes the screen but the process is still going. In other words: the process takes the same time with the API, only the screen freeze so the user see like 5%, 11%, 23%, 31%...

  9. #9

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287

    Re: Delay Progress Bar

    Quote Originally Posted by RhinoBull
    The point is if it takes so little time then you don't need to show progress - changing cursor to hourglass can be more than enough.
    Yes, that is right. Lets say the user adds 1000 files (optional), it is still fast, i want the user to see the progress bar for more than 2 seconds.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Delay Progress Bar

    [color=navy]But why make them wait 2 seconds or more if they only add 1 file? If the users get frustrated waiting everytime a file is added then they will be less likely to use your app.

    If its under a certain number of files then I would make it just same "complete" but if its over, say 1,000, then I would opt for the progressbar.[/coor]
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

  12. #12

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287

    Question Re: Delay Progress Bar

    Back after few days.
    I wrote some code.
    Now the problem is that it adds the files so fast that i can see the progressbar ok but the label which shows the percantage is NOT being updated fast enough. If I add 500 files in it will be ok until lets say the 105th file and then the percantage will get "stuck" on lets say 20%.
    I tried using Refresh for the form but nothing.
    Anyone?

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Delay Progress Bar

    How are you calculating/updating the labels percentage? Post code?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Delay Progress Bar

    Try to use DoEvents.
    Code:
        ... ...
        frmLoading.lblPercent.Caption = (i / Data.Files.Count) * 100 & "%"
        DoEvents
    Next i
    ... ...

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Delay Progress Bar

    But it shouldnt stop at 20%. Sounds like maybe there is something in the code that isnt correct.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Delay Progress Bar

    Before you say "But...", try that code or the simple code below (with then without DoEvents) you will see the different:
    Code:
    Private Sub Command1_Click()
       Dim i As Long
       For i = 1 To 10000
          Me.Label1.Caption = i / 10000 * 100 & "%"
          DoEvents
       Next
    End Sub

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Delay Progress Bar

    "But..."
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18
    Junior Member
    Join Date
    Feb 2007
    Posts
    26

    Re: Delay Progress Bar

    You could just do timers and use a shape for the progress bar. Set the timer delay to whatever you think is long enough for each item.

    Code:
    Private Sub Timer1_Timer()
    status.Caption = "Loading GUI"
    Timer1.Enabled = False
    Timer2.Enabled = True
    Shape1.Width = 1455
    End Sub
    Private Sub Timer2_Timer()
    status.Caption = "GUI Loaded"
    Timer2.Enabled = False
    Shape1.Width = 3000
    End Sub

  19. #19
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Delay Progress Bar

    "But..."

  20. #20

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287

    Re: Delay Progress Bar

    Quote Originally Posted by anhn
    Before you say "But...", try that code or the simple code below (with then without DoEvents) you will see the different:
    Code:
    Private Sub Command1_Click()
       Dim i As Long
       For i = 1 To 10000
          Me.Label1.Caption = i / 10000 * 100 & "%"
          DoEvents
       Next
    End Sub
    DoEvents doesnt work. I mean it works but doesnt solve the problem. It really slow down the process a bit.
    The code is fine, the Percantage is fine. If i call a MsgBox to pop up and show the percantage every once in a while in the process, it will show the correct percantage. The problem is that its too fast to see it. the label doesnt refresh or soemthing.

  21. #21
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Delay Progress Bar

    Well thats what will happen when you use doEvents because it takes a slice of the cpu cycles to allow the process to upgrade/redraw the GUI.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  22. #22
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Delay Progress Bar

    Quote Originally Posted by Stiletto
    ... It really slow down the process a bit.
    ... The problem is that its too fast to see it. ...
    That's a bit of crazy. Usually I want my code to run as fast as possible.
    Usually I came back to my code to modify it to make it run faster.

    Now, the DoEvents allows the Label to be redrawed one by one value instead of jumping.
    If you want to slow it down more then you can add Sleep() into the Loop after DoEvents.
    Other way, if you don't want to use Sleep() API function then you can waste a bit of resource to slow it down by using Timer() function like this:
    Code:
       Dim i As Long
       Dim t as Single '-- for without using Sleep()
    
       For i = 1 To 10000
          Me.Label1.Caption = i / 10000 * 100 & "%"
          DoEvents
          '-- delay 2 seconds here
          'Sleep 2000 '-- Sleep() API need to be declared
          t = Timer : While (Timer - t) < 2 : Wend
       Next

  23. #23
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Delay Progress Bar

    Quote Originally Posted by Stiletto
    Code:
    frmLoading.lblTitle.Caption = "Loading Files..."
    frmLoading.ProgressBar.Max = Data.Files.Count
    frmLoading.ProgressBar.Value = 0
    frmMain.MousePointer = 11
    frmLoading.MousePointer = 11
    frmLoading.Show '1, Me
    frmMain.Enabled = False
    For i = 1 To Data.Files.Count
        Call AddFiles(Data.Files(i), listFiles.ListItems.Count + 1)
        frmLoading.ProgressBar.Value = i
        frmLoading.lblFiles.Caption = i & " Of " & Data.Files.Count
        frmLoading.lblPercent.Caption = (i / Data.Files.Count) * 100 & "%"
        Pause 1    ' pause 1 second on each loop
    Next i
    frmMain.Enabled = True
    Unload frmLoading
    frmMain.MousePointer = 0
    frmLoading.MousePointer = 0
    I use this 'Pause Sub' darn near anywhere I want to add a delay. Note where I put the 'Pause' statement in your code. The lower limit is .005 Sec (500mS). I don't think it has an upper limit, but I avoid long delay times (Minutes) because it will suck up processor cycles.

    Code:
    Private Sub Pause(ByVal Delay As Single)    'Pause Sub Cred: 'Wayne Spangler' a1vbcode.com
        Dim X As Single
        X = Timer + Delay                  ' Add a delay to the current time
        Do While X > Timer                 ' and waits for the current time
            DoEvents                       ' to catch up.
        Loop                               ' Pause & Delay can be any name, but
    End Sub                                ' references to them must also be changed.
    Last edited by CDRIVE; Jan 17th, 2008 at 08:56 AM.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

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