Kyle Kyle - 7 months ago 16
Vb.net Question

For some reason my input values will not show and my Chr(149) will not output correctly

I have this procedure and I cannot get it to output my input numbers as well as the correct number of dots to go along with the corresponding grade.

Example for output should be:

High Grade ********* 94

Low Grade ******* 75

Range ** 19

Average ******** 85

with the "*" representing the dots being the grade divided by 10

But for some reason I am getting ** 0.00 for all of my values.

Private Sub btnStats_Click(sender As Object, e As EventArgs) Handles btnStats.Click
If DataOk() Then
Dim max, min, sum As Double
Dim dots As String = ""


lstOutput.Items.Clear()
lstOutput.Items.Add("Student Letter Grade Summary")
lstOutput.Items.Add("Course - " & txtCourse.Text)
lstOutput.Items.Add("Semester - " & txtSemester.Text)
DisplaySummary(dots, max, min, sum)
ProcessSummary(max, min, sum)

End If

End Sub
Sub ProcessSummary(ByRef max As Double, ByRef min As Double, ByRef sum As Double)
Dim grade As Integer

min = 0
max = 100
For i As Integer = 0 To lstGrade.Items.Count - 1
grade = CInt(lstGrade.Items(i))
If grade > min Then
min = grade
End If
If grade < max Then
max = grade
End If
sum += grade
Next
End Sub
Sub DisplaySummary(ByRef dots As String, ByRef max As Double, ByRef min As Double, ByRef range As Double)
lstOutput.Items.Clear()
lstOutput.Items.Add("High grade " & " " & LineOfDots(CType(max / 10, String)) & max.ToString("n2"))
lstOutput.Items.Add("Low grade " & " " & LineOfDots(CType(min / 10, String)) & min.ToString("n2"))
lstOutput.Items.Add("Range " & " " & LineOfDots(CType(max - min / 10, String)) & (max - min).ToString("n2"))
lstOutput.Items.Add("Average " & " " & LineOfDots(CType(max + min / 10, String)) & ((max + min) / 2).ToString("n2"))

End Sub
Function LineOfDots(ByVal dots As String) As String
For i As Integer = 1 To lstGrade.Items.Count - 1
LineOfDots &= Chr(149)
Next

Return LineOfDots
End Function

Answer

Change LineOfDots() to receive an Integer and use the String Constructor like this:

Function LineOfDots(ByVal dots As Integer) As String
    Return New String(Chr(149), dots)
End Function

Then here would be a new example of how to call it:

lstOutput.Items.Add("High grade " & LineOfDots(max / 10) & " " & max.ToString("n2"))