Progressbar

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fniles

    #1

    Progressbar

    I am using VS 2005.
    I read a file using streamreader.
    I want to set the progressbar based on where I am in the file. How can I do
    that ?
    Thank you.

    sr = New StreamReader(sF ileName)
    line = sr.ReadLine
    ProgressBar1.Ma ximum = 800 --how to set the maximum property without
    reading the whole file first ?
    ProgressBar1.Mi nimum = 0
    ProgressBar1.St ep = 1
    ProgressBar1.Va lue = 0
    Do While line <Nothing
    ProgressBar1.Pe rformStep()
    :
    line = sr.ReadLine
    Loop


  • RickH

    #2
    Re: Progressbar

    On Apr 12, 4:13 pm, "fniles" <fni...@pfmail. comwrote:
    I am using VS 2005.
    I read a file using streamreader.
    I want to set the progressbar based on where I am in the file. How can I do
    that ?
    Thank you.
    >
    sr = New StreamReader(sF ileName)
    line = sr.ReadLine
    ProgressBar1.Ma ximum = 800 --how to set the maximum property without
    reading the whole file first ?
    ProgressBar1.Mi nimum = 0
    ProgressBar1.St ep = 1
    ProgressBar1.Va lue = 0
    Do While line <Nothing
    ProgressBar1.Pe rformStep()
    :
    line = sr.ReadLine
    Loop

    Before entering your read loop grab the length of the file using
    FileInfo:

    Dim fi As FileInfo = New FileInfo(sFileN ame)
    ProgressBar1.Ma ximum = fi.Length
    ProgressBar1.Mi nimum = 0

    Once minimum and Maximum are set then just then just keep track of
    your bytes read count and each time through the loop set the progress
    Value property

    Do While ...
    line = sr.ReadLine
    ....
    ....
    ....
    ProgressBar1.Va lue = sr.BaseStream.P osition
    Loop


    Comment

    • fniles

      #3
      Re: Progressbar

      Thank you.
      So, I do not need to do ProgressBar1.Pe rformStep() anymore (instead replace
      that with ProgressBar1.Va lue = sr.BaseStream.P osition) ?


      "RickH" <passport@windc restsoftware.co mwrote in message
      news:1176414587 .766947.83430@l 77g2000hsb.goog legroups.com...
      On Apr 12, 4:13 pm, "fniles" <fni...@pfmail. comwrote:
      >I am using VS 2005.
      >I read a file using streamreader.
      >I want to set the progressbar based on where I am in the file. How can I
      >do
      >that ?
      >Thank you.
      >>
      >sr = New StreamReader(sF ileName)
      >line = sr.ReadLine
      >ProgressBar1.M aximum = 800 --how to set the maximum property without
      >reading the whole file first ?
      >ProgressBar1.M inimum = 0
      >ProgressBar1.S tep = 1
      >ProgressBar1.V alue = 0
      >Do While line <Nothing
      > ProgressBar1.Pe rformStep()
      >:
      > line = sr.ReadLine
      >Loop
      >
      >
      Before entering your read loop grab the length of the file using
      FileInfo:
      >
      Dim fi As FileInfo = New FileInfo(sFileN ame)
      ProgressBar1.Ma ximum = fi.Length
      ProgressBar1.Mi nimum = 0
      >
      Once minimum and Maximum are set then just then just keep track of
      your bytes read count and each time through the loop set the progress
      Value property
      >
      Do While ...
      line = sr.ReadLine
      ...
      ...
      ...
      ProgressBar1.Va lue = sr.BaseStream.P osition
      Loop
      >
      >

      Comment

      • RickH

        #4
        Re: Progressbar

        On Apr 12, 8:57 am, "fniles" <fni...@pfmail. comwrote:
        Thank you.
        So, I do not need to do ProgressBar1.Pe rformStep() anymore (instead replace
        that with ProgressBar1.Va lue = sr.BaseStream.P osition) ?
        >
        "RickH" <passp...@windc restsoftware.co mwrote in message
        >
        news:1176414587 .766947.83430@l 77g2000hsb.goog legroups.com...
        >
        >
        >
        On Apr 12, 4:13 pm, "fniles" <fni...@pfmail. comwrote:
        I am using VS 2005.
        I read a file using streamreader.
        I want to set the progressbar based on where I am in the file. How can I
        do
        that ?
        Thank you.
        >
        sr = New StreamReader(sF ileName)
        line = sr.ReadLine
        ProgressBar1.Ma ximum = 800 --how to set the maximum property without
        reading the whole file first ?
        ProgressBar1.Mi nimum = 0
        ProgressBar1.St ep = 1
        ProgressBar1.Va lue = 0
        Do While line <Nothing
        ProgressBar1.Pe rformStep()
        :
        line = sr.ReadLine
        Loop
        >
        Before entering your read loop grab the length of the file using
        FileInfo:
        >
        Dim fi As FileInfo = New FileInfo(sFileN ame)
        ProgressBar1.Ma ximum = fi.Length
        ProgressBar1.Mi nimum = 0
        >
        Once minimum and Maximum are set then just then just keep track of
        your bytes read count and each time through the loop set the progress
        Value property
        >
        Do While ...
        line = sr.ReadLine
        ...
        ...
        ...
        ProgressBar1.Va lue = sr.BaseStream.P osition
        Loop- Hide quoted text -
        >
        - Show quoted text -
        Yes, but remember that the current base stream position may be way
        ahead of the current position your application code is at. This is
        because the base stream reads the file in buffer blocks, but your app
        is reading a line at a time. So what you can do is keep your own
        counter of the total number of bytes you've read and use that value to
        set the progress bar value.

        like this:

        dim myCounter as integer = 0
        Do While ...
        line = sr.ReadLine
        myCounter += line.length
        ...
        ...
        ...
        ProgressBar1.Va lue = myCounter
        Loop


        Comment

        • fniles

          #5
          Re: Progressbar

          Thank you very much.

          "RickH" <passport@windc restsoftware.co mwrote in message
          news:1176473612 .925781.235910@ n76g2000hsh.goo glegroups.com.. .
          On Apr 12, 8:57 am, "fniles" <fni...@pfmail. comwrote:
          >Thank you.
          >So, I do not need to do ProgressBar1.Pe rformStep() anymore (instead
          >replace
          >that with ProgressBar1.Va lue = sr.BaseStream.P osition) ?
          >>
          >"RickH" <passp...@windc restsoftware.co mwrote in message
          >>
          >news:117641458 7.766947.83430@ l77g2000hsb.goo glegroups.com.. .
          >>
          >>
          >>
          On Apr 12, 4:13 pm, "fniles" <fni...@pfmail. comwrote:
          >I am using VS 2005.
          >I read a file using streamreader.
          >I want to set the progressbar based on where I am in the file. How can
          >I
          >do
          >that ?
          >Thank you.
          >>
          >sr = New StreamReader(sF ileName)
          >line = sr.ReadLine
          >ProgressBar1.M aximum = 800 --how to set the maximum property
          >without
          >reading the whole file first ?
          >ProgressBar1.M inimum = 0
          >ProgressBar1.S tep = 1
          >ProgressBar1.V alue = 0
          >Do While line <Nothing
          > ProgressBar1.Pe rformStep()
          >:
          > line = sr.ReadLine
          >Loop
          >>
          Before entering your read loop grab the length of the file using
          FileInfo:
          >>
          Dim fi As FileInfo = New FileInfo(sFileN ame)
          ProgressBar1.Ma ximum = fi.Length
          ProgressBar1.Mi nimum = 0
          >>
          Once minimum and Maximum are set then just then just keep track of
          your bytes read count and each time through the loop set the progress
          Value property
          >>
          Do While ...
          line = sr.ReadLine
          ...
          ...
          ...
          ProgressBar1.Va lue = sr.BaseStream.P osition
          Loop- Hide quoted text -
          >>
          >- Show quoted text -
          >
          Yes, but remember that the current base stream position may be way
          ahead of the current position your application code is at. This is
          because the base stream reads the file in buffer blocks, but your app
          is reading a line at a time. So what you can do is keep your own
          counter of the total number of bytes you've read and use that value to
          set the progress bar value.
          >
          like this:
          >
          dim myCounter as integer = 0
          Do While ...
          line = sr.ReadLine
          myCounter += line.length
          ...
          ...
          ...
          ProgressBar1.Va lue = myCounter
          Loop
          >
          >

          Comment

          Working...