Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. adding progress bar

adding progress bar

Scheduled Pinned Locked Moved Visual Basic
help
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnjsm
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • J johnjsm

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        J Offline
        J Offline
        johnjsm
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • J johnjsm

          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

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups