From Inputbox to Listbox

Alright folks...I'm new to this visual basic stuff, and to the site. I am working on an assignment for a'll probably look pretty easy to the rest of you, but I just can't figure it out.

What I need to do is take the information from the input box, the 'quiz scores' that are entered and put them in the list box. The way it is set up now, as you'll see is that it takes the last score and enters it all 5 times. It appears that all of my other calculations work. I'm not looking for someone to completely write the code for me, as I really need to and want to learn this...but maybe just a little 'shove' in the right direction?!

Below is all of the code I have so far: I changed the part I need help with to red font so you can find it quicker...Thanks!!!!!

' Project: IT Department Grades
' Purpose: Allows the user to enter 5 scores, they will be displayed in a list box
' and then can be used to calculate the average and a grade letter will
' be displayed.
' Created by: Lisa Bastian on 9/27/08

Option Strict On
Option Explicit On

Public Class GradeForm

Dim strInputQuiz As String
Dim intQuizCounter As Integer = 1
Dim strGrade As String
Dim intQuizPoints As Integer
Dim intPointsAccumulator As Integer
Dim intAverage As Integer
Dim isConverted As Boolean

Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
End Sub

Private Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
lblTotalPoints.Text = ""
lblAveragePoints.Text = ""
lblLetterGrade.Text = ""

End Sub

Private Sub btnAcceptGrades_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAcceptGrades.Click

' repeats input box until all 5 grades have been entered
Do While intQuizCounter < 6
' input box for user to enter the numeric grades
strInputQuiz = InputBox("Please enter quiz grades " & intQuizCounter, "Quiz Grades")

' if points entered are correct numbers count the quiz and add the points
' in the points accumulator if not show message box saying re-enter
isConverted = Integer.TryParse(strInputQuiz, intQuizPoints)
If isConverted Then
intQuizCounter = intQuizCounter + 1
intPointsAccumulator = intPointsAccumulator + intQuizPoints

MessageBox.Show("Please re-enter quiz grade.", "Quiz Grades Error", MessageBoxButtons.OK, _

End If
[color=Red] ' Converts the Quiz Points entered to string and adds them
' to the list box
lstGrades.Text = Convert.ToString(intQuizPoints)

End Sub

Private Sub btnCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
' uses the numeric grades entered in the list box
' to give the average grade, which will be displayed as a
' letter grade

lblTotalPoints.Text = Convert.ToString(intPointsAccumulator)

lblAveragePoints.Text = Convert.ToString(intPointsAccumulator / 5)

intAverage = CInt(Convert.ToString(intPointsAccumulator / 5))
lblAveragePoints.Text = Convert.ToString(intAverage)

Select Case intAverage
Case Is >= 93
strGrade = "A"
Case Is >= 86
strGrade = "B"
Case Is >= 77
strGrade = "C"
Case Is >= 70
strGrade = "D"
Case Else
strGrade = "F"
End Select

' displays the letter grade in the label
lblLetterGrade.Text = strGrade
End Sub
End Class


  • seancampbellseancampbell Pennsylvania, USA
    If I understand correctly, you want to prompt the user to enter a value and then add that to your listbox? I have found that "InputBoxes" are annoying to the user, but if this is a tool for yourself or your IT Dept, then it shouldn't be too bad. If you will have a lot of end users, I would suggest having a button skim values from textboxes.

    To do what you want:

    Dim Val as String = ""
    Dim dPercent as Double = 0

    Val = InputBox("Please enter a Quiz Score.", "Score")
    If isNumeric(Val) then
    dPercent = cDbl(Val)
    'any other code you'd like, we just filled dPercent with the entered quiz score
    MsgBox("You entered a numeric value of " & dPercent.toString())
    MsgBox("You must enter a numeric value.)
    End If


    So let's say for instance you would like to continue to prompt the user until he enters a good value. This would be how you do that.

    Dim Val as String = ""
    Dim dPercent as Double = 0
    Dim Resolve as Boolean = false

    Do While Not Resolve

    Val = InputBox("Please enter a Quiz Score.", "Score")

    If isNumeric(Val) then
    dPercent = cDbl(Val)
    Resolve = True
    MsgBox("Please enter a numeric value.")
    End If



    Happy Coding,
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion