Results 1 to 4 of 4

Thread: [2005] Trivial Percent Question

  1. #1

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Resolved [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:
    1. Dim intCount As Integer = 1
    2.         Dim decTotal As Decimal = 0
    3.         Dim strNumOfTests As String
    4.         Dim strTotalTests As String
    5.         Dim intNumOfTests As Integer
    6.  
    7.  
    8.  
    9.         'Display input box for the number of tests
    10.         strNumOfTests = InputBox("How many tests need to be graded? " _
    11.         , "Number of tests", "5")
    12.         intNumOfTests = CInt(strNumOfTests)
    13.  
    14.         Do Until intCount > CInt(strNumOfTests)
    15.  
    16.             strTotalTests = InputBox("Please enter the score for test # " _
    17.             & intCount.ToString, "Test Scores")
    18.             intCount += 1
    19.             decTotal += CDec(strTotalTests)
    20.  
    21.         Loop
    22.  
    23.         'Make the If statements that are going to provide
    24.         'a letter grade with the socre.
    25.  
    26.         If decTotal >= 90 Then
    27.             lblAverageScore.Text = ("You scored " & FormatPercent(decTotal.ToString, 2) _
    28.             & " 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.

  2. #2
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641

    Re: [2005] Trivial Percent Question

    VB Code:
    1. Dim intCount As Integer = 1
    2.         Dim decTotal As Decimal = 0
    3.         Dim strNumOfTests As String
    4.         Dim strTotalTests As String
    5.         Dim intNumOfTests As Integer
    6.  
    7.  
    8.  
    9.         'Display input box for the number of tests
    10.         strNumOfTests = InputBox("How many tests need to be graded? " _
    11.         , "Number of tests", "5")
    12.         intNumOfTests = CInt(strNumOfTests)
    13.  
    14.         Do Until intCount > CInt(strNumOfTests)
    15.  
    16.             strTotalTests = InputBox("Please enter the score for test # " _
    17.             & intCount.ToString, "Test Scores")
    18.             intCount += 1
    19.             decTotal += CDec(strTotalTests)
    20.  
    21.         Loop
    22.  
    23.         'Make the If statements that are going to provide
    24.         'a letter grade with the socre.
    25.  
    26.         If decTotal >= 90 Then
    27.             lblAverageScore.Text = ("You scored " & FormatPercent((decTotal / 100).ToString, 2) _
    28.             & " which is an A.  Good Job!")
    Martin J Wallace (Slaine)

  3. #3

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Trivial Percent Question

    From the help topic for the FormatPercent function:
    VB Code:
    1. Dim TestNumber As Single = 0.76
    2. ' Returns "76.00%".
    3. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width