由于某种原因,我的输入值将不会显示,我的Chr(149)将无法正确输出

时间:2016-04-28 02:55:18

标签: vb.net

我有这个程序,我无法输出我的输入数字以及与相应等级一起输入的正确点数。

输出示例应为:
高等级********* 94
低年级******* 75
范围** 19
平均******** 85

使用" *"表示作为等级的点除以10

但出于某种原因,我的所有价值都得到了** 0.00。

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

1 个答案:

答案 0 :(得分:1)

更改LineOfDots()以接收整数并使用String Constructor,如下所示:

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

然后这将是一个如何调用它的新例子:

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