adding progress bar
-
Hi, I need to add a progress bar that will progress with the amount of bytes read of a file. I am performing a CRC32 on a large file and I would like to display the progress using the progress bar and also text displaying the percentage done. The crc32 is already running on a seperate thread. Can anyone help. This is the code for getting the crc32 Dim f As FileStream = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 8192) crc = c32.GetCrc32(f) lblCRC32V.Text = Hex(crc) f.Close() Thanks
-
Hi, I need to add a progress bar that will progress with the amount of bytes read of a file. I am performing a CRC32 on a large file and I would like to display the progress using the progress bar and also text displaying the percentage done. The crc32 is already running on a seperate thread. Can anyone help. This is the code for getting the crc32 Dim f As FileStream = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 8192) crc = c32.GetCrc32(f) lblCRC32V.Text = Hex(crc) f.Close() Thanks
If this CRC library you're using exposes a method to report progress, you'll be in business. If not, you won't be able to do this unless you have access to the source code for the library and add support for reporting progress. Does the library support this?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
If this CRC library you're using exposes a method to report progress, you'll be in business. If not, you won't be able to do this unless you have access to the source code for the library and add support for reporting progress. Does the library support this?
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Hi Dave, This is the code used for generating the CRC32
Public Class CRC32 ' This is v2 of the VB CRC32 algorithm provided by Paul ' (wpsjr1@succeed.net) - much quicker than the nasty ' original version I posted. Excellent work! Private crc32Table() As Integer Private Const BUFFER_SIZE As Integer = 1024 Public Function GetCrc32(ByRef stream As System.IO.Stream) As Integer Dim crc32Result As Integer crc32Result = &HFFFFFFFF Dim buffer(BUFFER_SIZE) As Byte Dim readSize As Integer = BUFFER_SIZE Dim count As Integer = stream.Read(buffer, 0, readSize) Dim i As Integer Dim iLookup As Integer Dim tot As Integer = 0 Do While (count > 0) For i = 0 To count - 1 iLookup = (crc32Result And &HFF) Xor buffer(i) crc32Result = ((crc32Result And &HFFFFFF00) \ &H100) And &HFFFFFF ' nasty shr 8 with vb :/ crc32Result = crc32Result Xor crc32Table(iLookup) Next i count = stream.Read(buffer, 0, readSize) Loop GetCrc32 = Not (crc32Result) End Function Public Sub New() ' This is the official polynomial used by CRC32 in PKZip. ' Often the polynomial is shown reversed (04C11DB7). Dim dwPolynomial As Integer = &HEDB88320 Dim i As Integer, j As Integer ReDim crc32Table(256) Dim dwCrc As Integer For i = 0 To 255 dwCrc = i For j = 8 To 1 Step -1 If (dwCrc And 1) Then dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF dwCrc = dwCrc Xor dwPolynomial Else dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF End If Next j crc32Table(i) = dwCrc Next i End Sub End Class Public Class GetCRC32OF Public Sub CRC32File() End Sub End Class
-
Hi Dave, This is the code used for generating the CRC32
Public Class CRC32 ' This is v2 of the VB CRC32 algorithm provided by Paul ' (wpsjr1@succeed.net) - much quicker than the nasty ' original version I posted. Excellent work! Private crc32Table() As Integer Private Const BUFFER_SIZE As Integer = 1024 Public Function GetCrc32(ByRef stream As System.IO.Stream) As Integer Dim crc32Result As Integer crc32Result = &HFFFFFFFF Dim buffer(BUFFER_SIZE) As Byte Dim readSize As Integer = BUFFER_SIZE Dim count As Integer = stream.Read(buffer, 0, readSize) Dim i As Integer Dim iLookup As Integer Dim tot As Integer = 0 Do While (count > 0) For i = 0 To count - 1 iLookup = (crc32Result And &HFF) Xor buffer(i) crc32Result = ((crc32Result And &HFFFFFF00) \ &H100) And &HFFFFFF ' nasty shr 8 with vb :/ crc32Result = crc32Result Xor crc32Table(iLookup) Next i count = stream.Read(buffer, 0, readSize) Loop GetCrc32 = Not (crc32Result) End Function Public Sub New() ' This is the official polynomial used by CRC32 in PKZip. ' Often the polynomial is shown reversed (04C11DB7). Dim dwPolynomial As Integer = &HEDB88320 Dim i As Integer, j As Integer ReDim crc32Table(256) Dim dwCrc As Integer For i = 0 To 255 dwCrc = i For j = 8 To 1 Step -1 If (dwCrc And 1) Then dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF dwCrc = dwCrc Xor dwPolynomial Else dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF End If Next j crc32Table(i) = dwCrc Next i End Sub End Class Public Class GetCRC32OF Public Sub CRC32File() End Sub End Class
OK. So add a little code to the main processing loop to fire an event every so often reporting the percentage complete. You consumer code should create an instance of this class, wireup the event you write and use the data from that event to update the progress bar.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007