VB格式化数字

时间:2013-12-16 21:28:54

标签: vb.net

愚蠢的格式化问题。当我运行它时,不是获得数字等级,而是获得1分,得分2和平均值的零。否则它完美无缺。考试周和我的大脑太累了,不能继续玩它。任何帮助将不胜感激!

Option Strict On
Public Class frmStudent
Dim students As Student()


Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
    Dim thisStudent As New Student(IDTextBox.Text, nameTextBox.Text, Convert.ToInt32(score1TextBox.Text), Convert.ToInt32(score2TextBox.Text))

    ReDim Preserve students(Student.Count - 1)
    students(Student.Count - 1) = thisStudent

    IDTextBox.Text = ""
    nameTextBox.Text = ""
    score1TextBox.Text = ""
    score2TextBox.Text = ""

End Sub

Private Sub displayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayButton.Click
    Dim fmtStr As String = "{0,-10}{1,10}{2,10}{3, 10}{4,10}"
    Dim form As New frmDisplay()
    Dim average As Double


    form.lstDisplay.Items.Clear()
    form.lstDisplay.Items.Add("There are " & Student.Count & " students.")
    form.lstDisplay.Items.Add(String.Format(fmtStr, "ID", "Name", "Score1", "Score2", "Avg Score"))

    For Each studentObj As Student In students
        form.lstDisplay.Items.Add(String.Format(fmtStr, studentObj.ID, studentObj.Name, studentObj.Score1, studentObj.Score2, average))
    Next
    form.Show()
    Me.Hide()
End Sub

End Class

0 个答案:

没有答案