|
-
Apr 19th, 2013, 06:58 PM
#1
Thread Starter
New Member
Issue with VB program
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
-
Apr 19th, 2013, 07:09 PM
#2
Re: Issue with VB program
Might one reasonably assume that ..
numofstudents = ("enter students")
... should actually be ...
numofstudents = InputBox("enter students")
?
Not that that's really how it should be done either but we've kinda given up hope on programming teachers having a clue so it will no doubt do!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 19th, 2013, 07:11 PM
#3
Frenzied Member
Re: Issue with VB program
try and post your code in code tags
example:
As to the question i think this your problem
numofstudents = ("enter students")
For i = 1 To numofstudents
-
Apr 19th, 2013, 10:06 PM
#4
Thread Starter
New Member
Re: Issue with VB program
 Originally Posted by dunfiddlin
Might one reasonably assume that ..
numofstudents = ("enter students")
... should actually be ...
numofstudents = InputBox("enter students")
?
Not that that's really how it should be done either but we've kinda given up hope on programming teachers having a clue so it will no doubt do!
This works much better.
Thanks for both of your responses!
Last edited by o2f2; Apr 19th, 2013 at 10:10 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|