convert to string error on GPA Average Calculator

GPA All Male, All Female, ALL students

Page 1 of 1

2 Replies - 2617 Views - Last Post: 26 February 2010 - 09:28 PM Rate Topic: -----

#1 JanetB2003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-February 10

convert to string error on GPA Average Calculator

Posted 26 February 2010 - 08:23 PM

GPA code help... GPA 1.0, 1.1, 1.2 through 4.0 alredy entered in a listbox in properties; radFemale, radMale, btnCalc btnExit: lblMale, lblFemale, lblAll to store averages. There are no text boxes. Please look at my code and tell me what I'm missing.... I'm sure it has something to do with the listbox...

Option Explicit On
Option Strict On
Option Infer Off

Public Class MainForm

    'closes the project
    Private Sub btnExit_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    'calculates the average GPA for Male Students, Female Students,
    'and ALL Students

    Private Sub btnCalc_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles btnCalc.Click

        'declare variables
        Dim lblMaleStudents As Integer
        Dim lblFemStudents As Integer
        Dim lblAllStudents As Integer
        Dim numCountMale As Integer = lstGPA.Items.Count
        Dim numCountFemale As Integer = lstGPA.Items.Count
        Dim sumMale As Double
        Dim sumFemale As Double

        'calculates and stores averages for male students
        If radMale.Checked Then
            For Each item As ListViewItem In lstGPA.Items
                sumMale += lstGPA.Items.Count
            Next
            lblMaleStudents = CInt(sumMale / numCountMale)
        Else
            'calculates and stores averages for female students
            If radFemale.Checked Then
                For Each item As ListViewItem In lstGPA.Items
                    sumFemale += lstGPA.Items.Count
                Next
                lblFemStudents = CInt(sumFemale / numCountFemale)
            End If
        End If
        'calculates All Students Average
        lblAllStudents = CInt((sumMale + sumFemale) / (numCountMale + numCountFemale))


    End Sub
End Class



Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: convert to string error on GPA Average Calculator

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: convert to string error on GPA Average Calculator

Posted 26 February 2010 - 09:09 PM

This is VB.NET code, not VB6. Moved to VB.NET forum. Also

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:


  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: convert to string error on GPA Average Calculator

Posted 26 February 2010 - 09:28 PM

For Each item As ListViewItem In lstGPA.Items
                sumMale += lstGPA.Items.Count
            Next

Don't you want to be doing something with the item?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1