Solved

Calculating percentage...

Posted on 2007-04-01
6
1,927 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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 …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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