Maximum property of ProgressBar

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

Hi,

I need advice on how to set the maximum property of my progress bar.

I read a huge file so I need a progress bar when I read it. However, I
don't know how many records are there in the file until I finish
reading it.

Anyone can advise me on how to set accurate maximum?

Thanks!
 
Hi,

I need advice on how to set the maximum property of my progress bar.

I read a huge file so I need a progress bar when I read it. However, I
don't know how many records are there in the file until I finish
reading it.

Anyone can advise me on how to set accurate maximum?

Thanks!

How about finding out the size of the file in bytes, then keeping
track of how many bytes you have read. Don't forget about the record
delimiter, which you may not see depending on how you read the file.
 
Curious,

I expect that you are talking about a text file, which is in fact fysical a
long string of characters.

In those are often CR or/and LF characters, but those can only be seen as
they are readed, and that is not your goal.

So see the solution from Jack as a very good alternative.

Cor
 
How about finding out the size of the file in bytes, then keeping
track of how many bytes you have read.  Don't forget about the record
delimiter, which you may not see depending on how you read the file.

Hi Jack,

Thanks for the suggestion! Definitely this is do-able although I'll
need to calculate the number of bytes I have read in the loop.

Could you tell me how to calculate the number of bytes for each line
of string?
 
Hi Jack,

Thanks for the suggestion! Definitely this is do-able although I'll
need to calculate the number of bytes I have read in the loop.

Could you tell me how to calculate the number of bytes for each line
of string?

It depends how you are reading each line. I presume you get the line
in a string variable. If so, then var.Length is the number of chars.
If the method you use to read the lines hides the line termination
characters, you need to count them too. I think I would assume two
termination characters per line, but check for the count getting too
high in case there is only one termination character.
 
Is var.Length a number of bytes? Or is there a formula to translate
number of chars to number of bytes?

I assume that I'll need a huge string to hold the entire content of
the file in order to get the number of maximum bytes before reading?
 
Is var.Length a number of bytes? Or is there a formula to translate
number of chars to number of bytes?

I assume that I'll need a huge string to hold the entire content of
the file in order to get the number of maximum bytes before reading?

The String.Length is the number of characters.

I presumed that if you are reading a file, you could find out the size
of the file from the file system (System.IO.FileInfo).

If the file is Ascii, then the number of bytes in the file will be the
same as the number of characters you read plus the number of record
delimiters.

If the file is Unicode, then the number of bytes will be twice the
number of characters. I'm not sure how to determine that.
 
If the file is Unicode, then the number of bytes will be twice the
number of characters. I'm not sure how to determine that.

Which is absolute not important for your solution, it is about the length
and the progress, the absolute values are not relevant.

:-)

Cor
 
Which is absolute not important for your solution, it is about the length
and the progress, the absolute values are not relevant.

:-)

Cor

It's very important.

Suppose the file contains 1000 bytes.

If the file contains Ascii characters, then (ignoring line ending
characters) the program will read 1000 characters.

If the file contains Unicode characters, then if the program reads the
file correctly (each Unicode character in the file becomes one string
character) the program will read 500 characters. If the program
doesn't deal with this, the progress bar will only go to 50%.
 
Hi Jack,

Thanks for the suggestion on using System.IO.FileInfo! It solved my
problem. At first, I get the length of the entire content of the file
by using System.IO.FileInfo. Then I read in the first line and get its
length. Then I divided the length of the entire content by the length
of the first line and come up with the count as mProgressBar.Maximum.

Since all of the lines are not precisely the same length, in order to
prevent mProgressBar.Value exceeding mProgressBar.Maximum, I check
this each time when I set mProgressBar.Value.

FYI, the characters are Ascii.
 
Jack,

The information given back is not in characters it is the size in bytes,
however as it were pears it would be the same.

The only thing you have to do then is see what is the progress in pears.

But that is not important for the progressbar, it only has to know what
percentage of the way to go is done.

Cor
 
Back
Top