Jump to content
xisto Community
jimmy89

Need Help With Rounding Integers

Recommended Posts

Hi,
I'm am making this project and I need a progress bar for the status of the task. i have two values, total and total_pings which are described below
Total > The amount that I am currently up to
Total-Pings > Total amount

so, to find the work done as a percentage the code would be something like

Private Sub tracker()		Dim amount, final As Integer		amount = total /  total_pings		final = amount * 100		prgStatus.Value = finalEnd Sub

This would show me the percentage of work completed. But im having problems. When the program is running the progress bar doesn't change. it will sit on 0 till the 'total' value reaches 17 (half way) which then it goes to 100% and stops there.

What I'm thinking thats happening is that because the values are something like 0.235... VB is rounding the values back to 0. but when it reaches half way the values becomes 0.522... and it rounds to 1, which then makes the progress bar go to 100%.

My question is, how can i make VB not round the integers, or how can i complete this task with some simple code.

Thanks
-jimmy
Edited by Jimmy89 (see edit history)

Share this post


Link to post
Share on other sites

If you look under the properties of the progress bar (prgStatus). There's 2 properties which you need to take into consideration. Maximum and Minimum. On my VS2003, the default was 100 and 0 respectively. Maximum define at what value the progress bar shows fullscale, and Minimum is the value for zero progress.

If you were using the same default value, and since you multiple your amount by 100, that means it should be correct in this sense. You can try to put a break point at

prgStatus.Value = final

to see what value was pass over to the progress bar, or you can dump it via Debug.WriteLine. That might give you some clue as what's wrong.

Share this post


Link to post
Share on other sites

the values that it's coming up with is 1 (total) and 34 (total_pings), which then it evaluates 1 / 34 as 0 and not 0.029 which is what it should be. Is there anyway to stop it rounding the values back to zero?thanks-jimmy

Share this post


Link to post
Share on other sites

the values that it's coming up with is 1 (total) and 34 (total_pings), which then it evaluates 1 / 34 as 0 and not 0.029 which is what it should be. Is there anyway to stop it rounding the values back to zero?
thanks
-jimmy

Sorry, didn't notice that you declare "amount" as integer. Then try this
Dim final As Integer		Dim amount As Single		amount = total /  total_pings		final = amount * 100		prgStatus.Value = final-- OR -- if you don't need the immediate variable		final = total /  total_pings * 100-- If you turn Strict On		final = Cint(total /  total_pings * 100)
That should do the trick

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.