Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27400

VS 2010 updating new values.

$
0
0
Here is the state problem : 6. Display the average GPA for all the students, the average GPA for the male students and the average GPA for the female students. Your application must update these three average GPA for each time when user enters a new data set using the list boxes and click on calculate button.


I have been working on this program, but it isn't working at all! :(
When I run the program, it won't update any values, but will show the GPA for the currently selected items.
(i.e, if I had Male with GPA 1, then it showed total gpa: 1 and male gpa :1. Then, if I chose Female with GPA 2, then it should show Total gpa : 1.5 and male gpa : 1 and female gpa : 2, but instead it gives total gpa : 2 and female gpa 2.)
any ideas?


here is the code. "calculate" button code. ListBox1 is for gender selection, and ListBox2 is for GPA selection.
Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     

        Dim gender As String
        gender = Convert.ToString(ListBox1.SelectedItem)
        Dim gpa As Decimal
        gpa = Convert.ToDecimal(ListBox2.SelectedItem)
        Dim femaleGPA As Decimal
        Dim maleGPA As Decimal
        Dim totalGPA As Decimal
        Dim totalCounter As Integer
        Dim femaleCounter As Integer
        Dim maleCounter As Integer
        Dim totalGPAaccumulator As Decimal
        Dim femaleGPAaccumulator As Decimal
        Dim maleGPAaccumulator As Decimal
        Dim oldgpa As Decimal



        Select Case gender
            Case "F"
                femaleCounter = femaleCounter + 1
                femaleGPAaccumulator = gpa + oldgpa
                femaleGPA = femaleGPAaccumulator / femaleCounter
                Label8.Text = Convert.ToString(femaleGPA)
            Case "M"
                maleCounter += 1
                maleGPAaccumulator = gpa + oldgpa
                maleGPA = maleGPAaccumulator / maleCounter
                Label7.Text = Convert.ToString(maleGPA)
        End Select


        totalCounter += 1
        totalGPAaccumulator = gpa + oldgpa
        totalGPA = totalGPAaccumulator / totalCounter


        Label6.Text = Convert.ToString(totalGPA)




        oldgpa = gpa



    End Sub


Viewing all articles
Browse latest Browse all 27400


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>