|
-
Mar 5th, 2009, 11:18 AM
#1
Thread Starter
Fanatic Member
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
-
Mar 5th, 2009, 11:22 AM
#2
Thread Starter
Fanatic Member
Re: Progress Bar counting problems......
Ahhh............i am not incrementing CurVal. Duh!
-
Mar 5th, 2009, 11:27 AM
#3
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 -
-
Mar 5th, 2009, 11:28 AM
#4
Thread Starter
Fanatic Member
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
-
Mar 5th, 2009, 11:29 AM
#5
Re: Progress Bar counting problems......
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 -
-
Mar 5th, 2009, 11:32 AM
#6
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|