Solved

Calculating percentage...

Posted on 2007-04-01
6
1,920 Views
Last Modified: 2008-01-09
I need help calculating the percentage of two numbers.  I have two Labels with the values and need to calculate the percentage.

RealPercentage = CDec(Me.lblActualMilestoneHours.Text) \ CDec(Me.lblApprovedMilestone.Text)

The value of lblActualMilestoneHours is 5
The value of lblApprovedMilestone is 2

0
Comment
Question by:convertix
6 Comments
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 150 total points
ID: 18834274
Hello convertix,
Where are you getting hung up?
What are the meanings of those labels?
I'd suppose either you're getting an error, or you're getting incorrect data.
Have you tried flipping the values?
RealPercentage = CDec(Me.lblApprovedMilestone.Text) / CDec(Me.lblActualMilestoneHours.Text)

Or is it the you were using the backslash, rather than the forward slash?

~sirbounty
0
 

Author Comment

by:convertix
ID: 18834332
The lblApprovedMilestone is the total amount of hours and the lblActualMilestoneHours is the current number of hours in the current project.  This program is for keeping track of how many hours a developer is taking to complete a project.  The total approved hours is 5 for this milestone and the actual current hours on the project is 2 so I want to figure out the percentage done.  When I use my calculator I get the percentage 40%.  When I take the 5 and divide it by two in VB.NET I get 2 and I can't remember or figure out how to get the proper percentage.
0
 

Author Comment

by:convertix
ID: 18834335
I meant to say, when I take 2 and divide it by 5.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:convertix
ID: 18834336
And also meant to say....I get 0 (instead of 2)
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 150 total points
ID: 18834439
Look CLOSELY at the SLASHES in use.

Your code is using a Backslash "\" which means INTEGER Division will be peformed:
http://msdn2.microsoft.com/en-us/library/0e16fywh.aspx

sirbounty has corrected the problem by replacing it with a Forward Slash "/" which performs regular division.

So keep the variables in the order you have them but use the correct Operator:

    RealPercentage = CDec(Me.lblActualMilestoneHours.Text) / CDec(Me.lblApprovedMilestone.Text)
0
 
LVL 3

Accepted Solution

by:
r1937 earned 200 total points
ID: 18835349
ok ok math problem....

>>>>The lblApprovedMilestone is the total amount of hours and the lblActualMilestoneHours is the current number of hours in the current project.  This program is for keeping track of how many hours a developer is taking to complete a project.  The total approved hours is 5 for this milestone and the actual current hours on the project is 2 so I want to figure out the percentage done
<<<<<

Dim RealPercentage As Decimal
RealPercentage = CDec(Me.lblActualMilestoneHours.Text) / CDec(Me.lblApprovedMilestone.Text) * 100

r1937
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now