Dim Variable As Double

I am dimesioning a variable as a double because I need to store a floating point number but when I store the number it just store the integer part only. Why?


Dim tmpProgress As Double
tmpProgress = 100/6

ans then tmpProgress will = 17

What should I do?
Who is Participating?
PaulHewsConnect With a Mentor Commented:
If your Progressbar.Max = 100 then use code like this:

Dim tmpProgress As integer= CInt(CDbl(Step)/CDbl(Total) * 100)

where Step is the number of steps you've executed and Total is the total number of steps you need to execute.
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Use one of these instead:

        tmpProgress = 100.0 / 6.0
        tmpProgress = CDbl(100) / CDbl(6)
Try the following...the reason is that VB.NET thinks that the number 100 is an integer and the number 6 is an integer so when it divides them you should get an integer.

Dim d As Double
d = 100.0 / 6.0

If that is not working...make sure you are not performing any other operations on it.

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

MylorAuthor Commented:
Well, actually what I'm doing is using a progressbar.value to complete the 100% for a database load, but it seems that progressbar.value accept only int values.
MylorAuthor Commented:
What do you mean with the number of steps I've executed?
I think he is talking about "percentage complete".

I.E.~ if you have 10 total steps and you have completed 5.  If you plug that into his equation you will get 50%.

Mylor, thanks for the points.  As for the B grade, I would suggest that I thought the question was answered thoroughly enough.  Mind if I ask what we should have done to receive an "A" grade?  

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.