Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42220

Issue with VB program

$
0
0
I've written the following code to create a program that will allow the user to input number of students, their names, and grades. It will then display grade average in ListBox2 and drop lowest score to arrive at higher average in ListBox3. However, I am having an issue where VB states that "Conversion from string "enter students" to type 'Integer' is not valid." It ran fine before, and only when running the final test did it have trouble today.

Any help much appreciated!

Public Class Form1
Dim numofstudents As Integer
Dim namex(6) As String
Dim grade(6, 3) As Single
Dim total As Single
Dim lgrade As String

Private Sub XToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles XToolStripMenuItem.Click
Dim i As Integer
numofstudents = ("enter students")
For i = 1 To numofstudents
namex(i) = InputBox("name")
grade(i, 1) = InputBox("test one")
grade(i, 2) = InputBox("test two")
grade(i, 3) = InputBox("test three")
ListBox1.Items.Add(namex(i) & " " & grade(i, 1) & " " & grade(i, 2) & " " & grade(i, 3))
Next

End Sub

Private Sub Grade1ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles Grade1ToolStripMenuItem.Click
Dim i As Integer
Dim total As Single

For i = 1 To numofstudents
total = (grade(i, 1) + grade(i, 2) + grade(i, 3)) / 3

Call gcal()

ListBox2.Items.Add(namex(i) & " " & total & " " & lgrade)
Next
End Sub

Private Sub Grade2ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles Grade2ToolStripMenuItem.Click
Dim i, j As Integer
Dim total As Single
Dim low As Integer

For i = 1 To numofstudents
total = grade(i, 1) + grade(i, 2) + grade(i, 3)
low = 9999

For j = 1 To 3
If low > grade(i, j) Then
low = grade(i, j)
End If
Next

total = (total - low) / 2

Call gcal()

ListBox3.Items.Add(namex(i) & " " & total & " " & lgrade)
Next
End Sub
Sub gcal()
If total >= 90 Then
lgrade = "A"
Else
If total >= 80 And total < 90 Then
lgrade = "B"
Else
lgrade = "F"
End If
End If
End Sub
End Class

Viewing all articles
Browse latest Browse all 42220

Trending Articles



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