convert to string error on GPA Average Calculator

Page 1 of 1

2 Replies - 2734 Views - Last Post: 26 February 2010 - 09:28 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=158595&amp;s=302862db7da95187c0c23c8a8389a55b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 JanetB2003

Reputation: 0
• 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
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
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 =>

Thanks,
PsychoCoder

Is This A Good Question/Topic? 0

Replies To: convert to string error on GPA Average Calculator

#2 PsychoCoder

Reputation: 1645
• 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

• Saucy!

Reputation: 6203
• Posts: 23,940
• 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?