7 Replies - 622 Views - Last Post: 07 October 2012 - 01:18 AM Rate Topic: -----

#1 Cvet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-October 12

Can't get this test score to work, what am I doing wrong

Posted 06 October 2012 - 08:47 AM

Private Sub TextBox5_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtAverage.TextChanged
        ' This prodecure calculates the average test score of five scores and displays the average in lblAverage.  


        Dim TestScore1 As Integer        ' Test Score   
        Dim TestScore2 As Integer        ' Test Score 
        Dim TestScore3 As Integer        ' Test Score  
        Dim TestScore4 As Integer        ' Test Score 
        Dim TestScore5 As Integer        ' Test Score         
        Try

            ' Get the scores entered by the user  

            TestScore1 = TxtTestScore1.Text
            TestScore2 = TxtTestScore2.Text
            TestScore3 = TxtTestScore3.Text
            TestScore4 = TxtTestScore4.Text
            TestScore5 = TxtTestScore5.Text



            ' Calculate the average score  

            lblAverage.Text = (TestScore1 + TestScore2 + TestScore3 + TestScore4 + TestScore5) / 5

This post has been edited by AdamSpeight2008: 06 October 2012 - 02:19 PM
Reason for edit:: Someone forgot to use the CODE Tags.


Is This A Good Question/Topic? 0
  • +

Replies To: Can't get this test score to work, what am I doing wrong

#2 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,507
  • Joined: 16-March 11

Re: Can't get this test score to work, what am I doing wrong

Posted 06 October 2012 - 08:55 AM

Well you need to consider the conversion of data for the proper data types. What is the .Text property going to return? A string of course, so you need to convert it with something like

Integer.parse(txttestscore1.text)



Now that the text has been converted to an integer, and the testscore1 can now contain that integer. Give it a shot with the rest of the gang. :)
Was This Post Helpful? 0
  • +
  • -

#3 dotINSolution  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 16
  • Joined: 25-September 12

Re: Can't get this test score to work, what am I doing wrong

Posted 06 October 2012 - 08:58 AM

What really isn't working? That code seems to work fine very well here:
        Dim TestScore1 As Integer ' Test Score 1
        Dim TestScore2 As Integer ' Test Score 2
        Dim TestScore3 As Integer ' Test Score 3
        Dim TestScore4 As Integer ' Test Score 4
        Dim TestScore5 As Integer ' Test Score 5

        Try

            ' Get the scores entered by the user

            TestScore1 = 40
            TestScore2 = 70
            TestScore3 = 35
            TestScore4 = 69
            TestScore5 = 54

            ' Calculate the average score

            Dim average As Integer = (TestScore1 + TestScore2 + TestScore3 + TestScore4 + TestScore5) / 5

        Catch
        End Try



One thing i noticed is that in your code, that function is added to TxtAverage.TextChanged, are you sure you are attaching to the right handler.
Was This Post Helpful? 0
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,507
  • Joined: 16-March 11

Re: Can't get this test score to work, what am I doing wrong

Posted 06 October 2012 - 09:05 AM

The handler is incorrect, unless he wants it to calculate that average every single time a character is added, or removed from the Textbox5 control.
Was This Post Helpful? 0
  • +
  • -

#5 Cvet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-October 12

Re: Can't get this test score to work, what am I doing wrong

Posted 06 October 2012 - 09:09 AM

View PostdotINSolution, on 06 October 2012 - 08:58 AM, said:

What really isn't working? That code seems to work fine very well here:
        Dim TestScore1 As Integer ' Test Score 1
        Dim TestScore2 As Integer ' Test Score 2
        Dim TestScore3 As Integer ' Test Score 3
        Dim TestScore4 As Integer ' Test Score 4
        Dim TestScore5 As Integer ' Test Score 5

        Try

            ' Get the scores entered by the user

            TestScore1 = 40
            TestScore2 = 70
            TestScore3 = 35
            TestScore4 = 69
            TestScore5 = 54

            ' Calculate the average score

            Dim average As Integer = (TestScore1 + TestScore2 + TestScore3 + TestScore4 + TestScore5) / 5

        Catch
        End Try



One thing i noticed is that in your code, that function is added to TxtAverage.TextChanged, are you sure you are attaching to the right handler.


sorry grabbed the wrong one.. this is what i have
 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        ' This prodecure calculates the average test score of five scores and displays the average in lblAverage.  


        Dim TestScore1 As Integer        ' Test Score 1  
        Dim TestScore2 As Integer        ' Test Score 2  
        Dim TestScore3 As Integer        ' Test Score 3  
        Dim TestScore4 As Integer        ' Test Score 4
        Dim TestScore5 As Integer        ' Test Score 5 

        Try

            ' Get the scores entered by the user  

            TestScore1 = txtTestScore1.Text
            TestScore2 = TxtTestScore2.Text
            TestScore3 = TxtTestScore3.Text
            TestScore4 = TxtTestScore4.Text
            TestScore5 = TxtTestScore5.Text



            ' Calculate the average score  

            lblAverage = (TestScore1 + TestScore2 + TestScore3 + TestScore4 + TestScore5) / 5

        Catch ex As Exception

        End Try
        'error message'
        MessageBox.Show("Must contain numbers Only")
    End Sub
End Class

This post has been edited by AdamSpeight2008: 06 October 2012 - 02:20 PM

Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2270
  • View blog
  • Posts: 9,496
  • Joined: 29-May 08

Re: Can't get this test score to work, what am I doing wrong

Posted 06 October 2012 - 02:20 PM

Please learn to use the code tags.

This post has been edited by AdamSpeight2008: 06 October 2012 - 02:21 PM

Was This Post Helpful? 0
  • +
  • -

#7 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,507
  • Joined: 16-March 11

Re: Can't get this test score to work, what am I doing wrong

Posted 06 October 2012 - 04:57 PM

Convert the strings to integers, and ten perform your calculation. It should work fine. On a side note your error message does nothing but display the same message every single time you run the routine because it's not in any sort of error trap.
Was This Post Helpful? 0
  • +
  • -

#8 Cvet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-October 12

Re: Can't get this test score to work, what am I doing wrong

Posted 07 October 2012 - 01:18 AM

View Posttrevster344, on 06 October 2012 - 04:57 PM, said:

Convert the strings to integers, and ten perform your calculation. It should work fine. On a side note your error message does nothing but display the same message every single time you run the routine because it's not in any sort of error trap.


thanks, got it working!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1