Solved

# Dim Variable As Double

Posted on 2005-05-10
426 Views
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?

ie:

Dim tmpProgress As Double
tmpProgress = 100/6

ans then tmpProgress will = 17

What should I do?
0
Question by:Mylor

LVL 85

Assisted Solution

tmpProgress = 100.0 / 6.0
tmpProgress = CDbl(100) / CDbl(6)
0

LVL 7

Expert Comment

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
Console.WriteLine(d.ToString())

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

Later,
Eric
0

Author Comment

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

LVL 38

Accepted Solution

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

Author Comment

What do you mean with the number of steps I've executed?
0

LVL 7

Expert Comment

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

Later,
Eric
0

LVL 38

Expert Comment

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?

http://www.experts-exchange.com/help.jsp#hi73
0

## Featured Post

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

#### Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!