|
-
Feb 20th, 2007, 05:38 AM
#1
Thread Starter
Addicted Member
[2005] Trivial Percent Question
I have tried different conversions but after 45 minutes about out of ideas as to why when I run this prog I end up with 10,000.00% instead of 100.00%. As usual I searched format issues and percentage but turned up nothing relavent to me with in the first couple of pages.
Here is the code I'm using and the input i am using is 1 test to be graded and the grade is 100%.
VB Code:
Dim intCount As Integer = 1
Dim decTotal As Decimal = 0
Dim strNumOfTests As String
Dim strTotalTests As String
Dim intNumOfTests As Integer
'Display input box for the number of tests
strNumOfTests = InputBox("How many tests need to be graded? " _
, "Number of tests", "5")
intNumOfTests = CInt(strNumOfTests)
Do Until intCount > CInt(strNumOfTests)
strTotalTests = InputBox("Please enter the score for test # " _
& intCount.ToString, "Test Scores")
intCount += 1
decTotal += CDec(strTotalTests)
Loop
'Make the If statements that are going to provide
'a letter grade with the socre.
If decTotal >= 90 Then
lblAverageScore.Text = ("You scored " & FormatPercent(decTotal.ToString, 2) _
& " which is an A. Good Job!")
I know with in 5 minutes someone with far more experience then I have is going to nail this and make me look like an idiot but I'm willing to suffer the humiliation as long as I get an answer with a reason lol...
Later
Abe
Last edited by Abrium; Feb 20th, 2007 at 06:10 AM.
-
Feb 20th, 2007, 05:53 AM
#2
Fanatic Member
Re: [2005] Trivial Percent Question
VB Code:
Dim intCount As Integer = 1
Dim decTotal As Decimal = 0
Dim strNumOfTests As String
Dim strTotalTests As String
Dim intNumOfTests As Integer
'Display input box for the number of tests
strNumOfTests = InputBox("How many tests need to be graded? " _
, "Number of tests", "5")
intNumOfTests = CInt(strNumOfTests)
Do Until intCount > CInt(strNumOfTests)
strTotalTests = InputBox("Please enter the score for test # " _
& intCount.ToString, "Test Scores")
intCount += 1
decTotal += CDec(strTotalTests)
Loop
'Make the If statements that are going to provide
'a letter grade with the socre.
If decTotal >= 90 Then
lblAverageScore.Text = ("You scored " & FormatPercent((decTotal / 100).ToString, 2) _
& " which is an A. Good Job!")
Martin J Wallace (Slaine)
-
Feb 20th, 2007, 05:55 AM
#3
Thread Starter
Addicted Member
Re: [2005] Trivial Percent Question
Thats a pretty quick fix. Is it common to have to do division like that when dealing with percentage?
Thanks for the reply though
-
Feb 20th, 2007, 07:37 AM
#4
Re: [2005] Trivial Percent Question
From the help topic for the FormatPercent function:
VB Code:
Dim TestNumber As Single = 0.76
' Returns "76.00%".
Dim TestString As String = FormatPercent(TestNumber)
1.00 converts to 100.00%. That's how it's supposed to work and that's how it works. Always read the help. The expression RTFM applies to us who use software to write software as much as anyone else. If documentation is provided and you don't consult it then it should not be a surprise that not everything is clear.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|