Results 1 to 6 of 6

Thread: Progress Bar counting problems......

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Progress Bar counting problems......

    With the help of others here I was able to get some code working to create a dummy file to fill the remaining space of a flash drive. However, I have added a progress bar and can't figure out why it's not working. I declare a variable for the current value, min, & max properities of the progressbar and then increment it by 1 during each step of my FOR loop. However, I never see anything on the progress bar. Thanks for any help.

    Code:
     Dim CurVal As Integer
            Dim RandomNumber As Byte
    
            'Create the dummyfile to take up the remaining space on the drive
            Dim myStreamWriter As New IO.StreamWriter("C:\dummyfile.txt")
            dumProgBar.Minimum = 1
            dumProgBar.Maximum = RemSpace
            CurVal = 0
    
            For i As Integer = 1 To RemSpace
                RandomNumber = CByte(RandomClass.Next(0, 256))
                myStreamWriter.BaseStream.WriteByte(RandomNumber)
                dumProgBar.Value = CurVal + 1
            Next
    
            myStreamWriter.Close()
            myStreamWriter.Dispose()
            myStreamWriter = Nothing
    -Jeremy

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Re: Progress Bar counting problems......

    Ahhh............i am not incrementing CurVal. Duh!

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Progress Bar counting problems......

    That's because the program is too busy running the loop and it doesn't have a chance to update the UI. Proper way to do this is to run the long running task in a different thread. A quick fix is to stick application.DoEvents() in the loop. You want to call Application.DoEvents sparely though, instead of every iteration of the loop. So you can call it like once every 100 iterations or so. Put this in your loop and see what happens.
    Code:
    If i Mod 100 = 0 Then
        Application.DoEvents()
    End If
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Re: Progress Bar counting problems......

    Hmm.... still having issues after changing to this. Still nothing on the progress bar.

    Code:
     Dim CurVal As Integer
            Dim RandomNumber As Byte
    
            'Create the dummyfile to take up the remaining space on the drive
            Dim myStreamWriter As New IO.StreamWriter("C:\dummy.txt")
            dumProgBar.Minimum = 1
            dumProgBar.Maximum = RemSpace
            CurVal = 0
    
            For i As Integer = 1 To RemSpace
                RandomNumber = CByte(RandomClass.Next(0, 256))
                myStreamWriter.BaseStream.WriteByte(RandomNumber)
                CurVal = CurVal + 1
                dumProgBar.Value = CurVal
            Next
    
            myStreamWriter.Close()
            myStreamWriter.Dispose()
            myStreamWriter = Nothing

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Progress Bar counting problems......

    See my last post...
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Re: Progress Bar counting problems......

    That took care of it! thanks for the tip.

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