Results 1 to 4 of 4

Thread: Issue with VB program

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    7

    Question 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

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  3. #3
    Frenzied Member
    Join Date
    Aug 2009
    Location
    Los Angeles
    Posts
    1,335

    Re: Issue with VB program

    try and post your code in code tags
    example:
    Code:
     your code
    As to the question i think this your problem

    numofstudents = ("enter students")
    For i = 1 To numofstudents

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    7

    Re: Issue with VB program

    Quote Originally Posted by dunfiddlin View Post
    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
  •  



Click Here to Expand Forum to Full Width