Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Maximum property of ProgressBar

Reply
 
Old 06-02-2008   #1 (permalink)
Curious


 
 

Maximum property of ProgressBar

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!

My System SpecsSystem Spec
Old 06-02-2008   #2 (permalink)
Jack Jackson


 
 

Re: Maximum property of ProgressBar

On Mon, 2 Jun 2008 13:32:39 -0700 (PDT), Curious
<fir5tsight@xxxxxx> wrote:
Quote:

>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.
My System SpecsSystem Spec
Old 06-02-2008   #3 (permalink)
Cor Ligthert[MVP]


 
 

Re: Maximum property of ProgressBar

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

"Curious" <fir5tsight@xxxxxx> schreef in bericht
news:f763eac4-8312-43db-979b-09adeedf6c60@xxxxxx
Quote:

> 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!
My System SpecsSystem Spec
Old 06-03-2008   #4 (permalink)
Curious


 
 

Re: Maximum property of ProgressBar

On Jun 2, 5:13*pm, Jack Jackson <jjack...@xxxxxx> wrote:
Quote:

> On Mon, 2 Jun 2008 13:32:39 -0700 (PDT), Curious
>
> <fir5tsi...@xxxxxx> wrote:
Quote:

> >Hi,
>
Quote:

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

> >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.
>
Quote:

> >Anyone can advise me on how to set accurate maximum?
>
Quote:

> >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.
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?
My System SpecsSystem Spec
Old 06-03-2008   #5 (permalink)
Jack Jackson


 
 

Re: Maximum property of ProgressBar

On Tue, 3 Jun 2008 07:36:10 -0700 (PDT), Curious
<fir5tsight@xxxxxx> wrote:
Quote:

>On Jun 2, 5:13*pm, Jack Jackson <jjack...@xxxxxx> wrote:
Quote:

>> On Mon, 2 Jun 2008 13:32:39 -0700 (PDT), Curious
>>
>> <fir5tsi...@xxxxxx> wrote:
Quote:

>> >Hi,
>>
Quote:

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

>> >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.
>>
Quote:

>> >Anyone can advise me on how to set accurate maximum?
>>
Quote:

>> >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.
>
>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.

My System SpecsSystem Spec
Old 06-03-2008   #6 (permalink)
Curious


 
 

Re: Maximum property of ProgressBar

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?
My System SpecsSystem Spec
Old 06-03-2008   #7 (permalink)
Jack Jackson


 
 

Re: Maximum property of ProgressBar

On Tue, 3 Jun 2008 12:02:40 -0700 (PDT), Curious
<fir5tsight@xxxxxx> wrote:
Quote:

>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.
My System SpecsSystem Spec
Old 06-04-2008   #8 (permalink)
Cor Ligthert[MVP]


 
 

Re: Maximum property of ProgressBar

>
Quote:

> 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

My System SpecsSystem Spec
Old 06-04-2008   #9 (permalink)
Jack Jackson


 
 

Re: Maximum property of ProgressBar

On Wed, 4 Jun 2008 06:14:55 +0200, "Cor Ligthert[MVP]"
<notmyfirstname@xxxxxx> wrote:
Quote:
Quote:

>>
>> 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
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%.
My System SpecsSystem Spec
Old 06-21-2008   #10 (permalink)
Curious


 
 

Re: Maximum property of ProgressBar

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.

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Help display ProgressBar while ChildForm loads .NET General
Set Focus To Specific Property In Property Grid .NET General
How Much Maximum RAM you Use? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46