Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 132,256 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,168 people online right now. Registration is fast and FREE... Join Now!




GPA Averages

 
Reply to this topicStart new topic

GPA Averages, The instruction is to allow user to check if male or female and then f

lawalker
post 1 Apr, 2008 - 10:20 AM
Post #1


New D.I.C Head

*
Joined: 14 Feb, 2008
Posts: 10

I am not too far on my code. I attached my gui and would be helpful to know that I set it up correctly and that I am on the right track.

I don't know what strategy to use to allow user to input several different GPA's under male and female and then figure the averages. Any help would be greatly appreciated.
Thanks


vb

Public Class mainform

Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xcombinationLabel.Click

End Sub


Private Sub xexitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xexitButton.Click
Me.Close()
End Sub

Private Sub xcalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xcalculateButton.Click
Dim gpa As Decimal
Dim InpGpa As String
Const prompt As String = "Please enter GPA."
Dim prompt2 As String = "Would you like to enter another GPA?"
Dim isGPAok As Boolean

Do While InpGpa <> "Done"
InpGpa = InputBox("Type a name or Done to quit.")
If InpGpa <> "Done" Then Print(InpGpa)
Loop

End Sub

Private Sub mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.xgenderListbox.Items.Add("Male")
Me.xgenderListbox.Items.Add("Female")
Me.xgenderListbox.SelectedIndex = 0





End Sub



Private Sub xgenderListbox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xgenderListbox.SelectedIndexChanged

End Sub

Private Sub xaverageGPAGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xaverageGPAGroupBox.Enter

End Sub
End Class


This post has been edited by Master Pimp P. Flow: 1 Apr, 2008 - 01:53 PM
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 1 Apr, 2008 - 01:53 PM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,923



Thanked 117 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Moved to VB.NET smile.gif
User is online!Profile CardPM

Go to the top of the page

nofear217
post 2 Apr, 2008 - 12:25 PM
Post #3


D.I.C Head

Group Icon
Joined: 8 Nov, 2007
Posts: 144



Dream Kudos: 175
My Contributions


If it were me, I'd likely have a textbox that holds the values with a Listbox that could then have values added to it from the text box....along with a clear and calculate button. Then have the calculate button loop through the items in the listbox, adding them and then calculating the average....something like this

CODE

Public Class Form2

    Private Sub xbuttonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xbuttonAdd.Click

        lbGPA.Items.Add(txtGPA.Text)
        txtGPA.Text = ""
        txtGPA.Focus()

    End Sub

    Private Sub txtGPA_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtGPA.KeyPress

        If Asc(e.KeyChar) = Keys.Enter Then

            lbGPA.Items.Add(txtGPA.Text)
            txtGPA.Text = ""
            txtGPA.Focus()
            e.Handled = True

        End If

    End Sub

    Private Sub xcalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xcalculateButton.Click

        Dim count As Integer = lbGPA.Items.Count()
        Dim gpaTotal As Decimal = 0
        Dim gpaAvg As Decimal = 0

        For i As Integer = 0 To (count - 1)

            Dim current As Integer = i
            'Dim currVal As Decimal = lbGPA.Items.Item(current)

            gpaTotal += CType(lbGPA.Items.Item(current), Decimal)

        Next

        gpaAvg = gpaTotal / count

        lblResult.Text = "The average GPA is: " & Decimal.Round(gpaAvg, 2)

    End Sub

    Private Sub xbuttonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xbuttonClear.Click

        lbGPA.Items.Clear()

    End Sub

    Private Sub lbGPA_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbGPA.DoubleClick

        lbGPA.Items.Remove(lbGPA.SelectedItem)

    End Sub
End Class


At the end of the click event you can change the Decimal.Round number to whatever number you want for the number of decimal places. Hope this helps!
User is offlineProfile CardPM

Go to the top of the page

lawalker
post 2 Apr, 2008 - 07:15 PM
Post #4


New D.I.C Head

*
Joined: 14 Feb, 2008
Posts: 10

Ok, thank you for your reply no fear but i got it a little late. I am almost done but I still have a glich. Again the purpose is to allow the user to select a gender then a gpa and the program is to keep track of the average female gpa's, male gpa's and also combined gpa's. The problem is, my code returns 0 in all three of my labels. Any clue what i am doing wrong???? Thank You so much to whomever takes the time to reply.


vb

'Angela on April 1, 2008
'Purpose: Calculate Average GPA's
Option Strict On
Option Explicit On

Public Class mainform
Private Sub xexitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xexitButton.Click
Me.Close()
End Sub

Private Sub xcalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xcalculateButton.Click

Dim i As Integer 'counter
Dim imale As Integer 'male counter
Dim ifemale As Integer 'female counter
Dim accumulator As Decimal
Dim accumulatorM As Decimal
Dim accumulatorF As Decimal
Dim combinedAvg As Decimal
Dim maleavg As Decimal
Dim femaleavg As Decimal

maleavg = Convert.ToDecimal(Me.xgenderListbox.SelectedIndex)
femaleavg = Convert.ToDecimal(Me.xgenderListbox.SelectedIndex)
combinedAvg = Convert.ToDecimal(Me.xgenderListbox.SelectedIndex)
Decimal.TryParse(Me.xcombinedResultsLabel.Text, combinedAvg)
Decimal.TryParse(Me.xmaleavgResultsLabel.Text, maleavg)
Decimal.TryParse(Me.xfemaleResultsLabel.Text, femaleavg)

'average female gpa
If Me.xgenderListbox.SelectedIndex = 0 Then
i = i + 1
ifemale = ifemale + 1
accumulatorF = accumulatorF + femaleavg
accumulator = accumulator + combinedAvg
femaleavg = accumulatorF / ifemale
combinedAvg = accumulator / i
Me.xfemaleResultsLabel.Text = femaleavg.ToString
Me.xcombinedResultsLabel.Text = combinedAvg.ToString

Else
i = i + 1
imale = imale + 1
accumulatorM = accumulatorM + maleavg
accumulator = accumulator + combinedAvg
maleavg = accumulatorM / imale
combinedAvg = accumulator / i
Me.xmaleavgResultsLabel.Text = maleavg.ToString
Me.xcombinedResultsLabel.Text = combinedAvg.ToString
End If

End Sub

Private Sub mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.xgenderListbox.Items.Add("Male")
Me.xgenderListbox.Items.Add("Female")
Me.xgenderListbox.SelectedIndex = 0

For gpalistbox As Decimal = 2D To 4D Step 0.25D
Me.xGpaListBox.Items.Add(gpalistbox.ToString)
Next gpalistbox
Me.xGpaListBox.SelectedIndex = 0

End Sub

End Class


EDIT: Please use code tags => code.gif

This post has been edited by PsychoCoder: 2 Apr, 2008 - 08:05 PM
User is offlineProfile CardPM

Go to the top of the page

nofear217
post 3 Apr, 2008 - 07:59 AM
Post #5


D.I.C Head

Group Icon
Joined: 8 Nov, 2007
Posts: 144



Dream Kudos: 175
My Contributions


Could you post a screenshot of what your form looks like so I can see from where the inputs of data are coming?
User is offlineProfile CardPM

Go to the top of the page

lawalker
post 3 Apr, 2008 - 08:58 AM
Post #6


New D.I.C Head

*
Joined: 14 Feb, 2008
Posts: 10

QUOTE(nofear217 @ 3 Apr, 2008 - 08:59 AM) *

Could you post a screenshot of what your form looks like so I can see from where the inputs of data are coming?



could you tell me how to send you a screen shot?
User is offlineProfile CardPM

Go to the top of the page

nofear217
post 3 Apr, 2008 - 10:39 AM
Post #7


D.I.C Head

Group Icon
Joined: 8 Nov, 2007
Posts: 144



Dream Kudos: 175
My Contributions


You should just be able to copy (Alt+PrtScr) and then paste it into a post.
User is offlineProfile CardPM

Go to the top of the page

lawalker
post 3 Apr, 2008 - 10:50 AM
Post #8


New D.I.C Head

*
Joined: 14 Feb, 2008
Posts: 10

QUOTE(lawalker @ 3 Apr, 2008 - 09:58 AM) *

QUOTE(nofear217 @ 3 Apr, 2008 - 08:59 AM) *

Could you post a screenshot of what your form looks like so I can see from where the inputs of data are coming?



could you tell me how to send you a screen shot?


I will try to explain it to you in the mean time, the more i work on this the worse it gets.
I have a gender list box with male and female options. I also have a gpa list box with gpa's to choose from. In addition, I have a group box that will display my gpa results. One for Male one for female and one for the combination. The only two other buttons i have is a calculate and an exit button. I am also trying to post the GUI as this is due tomorrow and I don't have much time left to figure this out. Thanks for any help.
User is offlineProfile CardPM

Go to the top of the page

nofear217
post 3 Apr, 2008 - 12:26 PM
Post #9


D.I.C Head

Group Icon
Joined: 8 Nov, 2007
Posts: 144



Dream Kudos: 175
My Contributions


I guess what I'm trying to figure out is how you are separating the male and female gpas individually if you have a listbox with male/female (only 2) values and then another listbox with all the gpas of the males and females. That's why I was wanting to look at a screenshot so I could get a better idea of what we were working with. And I apologize, it looks like the copy and paste won't work in these forums. If you have windows/msn messenger you can contact me via jeremysydnor@hotmail.com and I'll see if we can't talk this through better in that manner rather than a forum.
User is offlineProfile CardPM

Go to the top of the page

lawalker
post 3 Apr, 2008 - 01:02 PM
Post #10


New D.I.C Head

*
Joined: 14 Feb, 2008
Posts: 10

QUOTE(nofear217 @ 3 Apr, 2008 - 01:26 PM) *

I guess what I'm trying to figure out is how you are separating the male and female gpas individually if you have a listbox with male/female (only 2) values and then another listbox with all the gpas of the males and females. That's why I was wanting to look at a screenshot so I could get a better idea of what we were working with. And I apologize, it looks like the copy and paste won't work in these forums. If you have windows/msn messenger you can contact me via jeremysydnor@hotmail.com and I'll see if we can't talk this through better in that manner rather than a forum.




That's exactly what I have, 2 list boxes per my instructors wishes. I will have access to MSN a little later and will try to show u my interface then. Thank you for your time.
(I have been working on this all day and now my code is totally wacked, looks worse than before)
User is offlineProfile CardPM

Go to the top of the page

RookieDDZ
post 8 Nov, 2008 - 04:09 PM
Post #11


New D.I.C Head

*
Joined: 8 Nov, 2008
Posts: 1

I'm coming across the same issue. What was this answer? My code is close to the same after I trashed mine. I saw hers was a better setup. Any news?
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 10:48PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month