Trying to update a progress bar - bad calculation (math)
Something's wrong with my math: I'm trying to update a ProgressBar, but the math I'm using is not right:
double gdValPerAnswer = 0.0;
. . .
gdValPerAnswer = GetCountOfQuestions() * 0.001;...I know it's wrong, but I don't know what the calculation should be...?
Writer / Photographer - http://www.feedbooks.com/userbook/3631- Tipo cambiadoWang, JieMSFT, Moderadorjueves, 19 de noviembre de 2009 10:59To help people with similar question come up with this post easier.
Respuestas
I tried:
double dValPerAnswer = 0.0;
. . .
dValPerAnswer = 100 / GetCountOfQuestions();
...and the value of gdValPerAnswer is 0 (zero)...?
Writer / Photographer - http://www.feedbooks.com/userbook/3631
I'm not following exactly what you are trying to do (where's gdValPerAnswer in your last post?) but, assuming GetCountOfQuestions returns an integer, then you are doing integer division. If 100 < GetCountOfQuestions() then the value will be truncated to 0.
Try this:
dValPerAnswer = 100.0 / (double)GetCountOfQuestions();- Marcado como respuestaWang, JieMSFT, Moderadorjueves, 19 de noviembre de 2009 10:59
Hi Clay,
Or you can just set the Minimum & Maximum properties before setting the Value property, that will define the possible value range and then you just set the value and don't need to calculate the percentage yourself.
Regards,
Jie
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback, please tell us.
The CodeFx Project
My Blog (in Simplified Chinese)- Marcado como respuestaWang, JieMSFT, Moderadorjueves, 19 de noviembre de 2009 10:59
Or you can just set the Minimum & Maximum properties before setting the Value property, that will define the possible value range and then you just set the value and don't need to calculate the percentage yourself.
Aha!
This was the best idea. All I had to do was:
giNumberOfQuestions = GetCountOfQuestions();
. . .
progBar.Minimum = 0;
progBar.Maximum = giNumberOfQuestions;. . .
//After correct answer provided:
progBar.Value = progBar.Value + 1;
Writer / Photographer - http://www.feedbooks.com/userbook/3631- Marcado como respuestaWang, JieMSFT, Moderadorjueves, 19 de noviembre de 2009 10:59
Todas las respuestas
- Hello,
if CountOfQuestions is the total count of questions to answer and the gdValPerAnswer is the count of questions answered, then:
percentage = gdValPerAnswer * 100 /CountOfQuestions;
Good Luck. - I tried:
double dValPerAnswer = 0.0;
. . .
dValPerAnswer = 100 / GetCountOfQuestions();
...and the value of gdValPerAnswer is 0 (zero)...?
Writer / Photographer - http://www.feedbooks.com/userbook/3631 I tried:
double dValPerAnswer = 0.0;
. . .
dValPerAnswer = 100 / GetCountOfQuestions();
...and the value of gdValPerAnswer is 0 (zero)...?
Writer / Photographer - http://www.feedbooks.com/userbook/3631
I'm not following exactly what you are trying to do (where's gdValPerAnswer in your last post?) but, assuming GetCountOfQuestions returns an integer, then you are doing integer division. If 100 < GetCountOfQuestions() then the value will be truncated to 0.
Try this:
dValPerAnswer = 100.0 / (double)GetCountOfQuestions();- Marcado como respuestaWang, JieMSFT, Moderadorjueves, 19 de noviembre de 2009 10:59
Hi Clay,
Or you can just set the Minimum & Maximum properties before setting the Value property, that will define the possible value range and then you just set the value and don't need to calculate the percentage yourself.
Regards,
Jie
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback, please tell us.
The CodeFx Project
My Blog (in Simplified Chinese)- Marcado como respuestaWang, JieMSFT, Moderadorjueves, 19 de noviembre de 2009 10:59
Or you can just set the Minimum & Maximum properties before setting the Value property, that will define the possible value range and then you just set the value and don't need to calculate the percentage yourself.
Aha!
This was the best idea. All I had to do was:
giNumberOfQuestions = GetCountOfQuestions();
. . .
progBar.Minimum = 0;
progBar.Maximum = giNumberOfQuestions;. . .
//After correct answer provided:
progBar.Value = progBar.Value + 1;
Writer / Photographer - http://www.feedbooks.com/userbook/3631- Marcado como respuestaWang, JieMSFT, Moderadorjueves, 19 de noviembre de 2009 10:59

