我可以重新使用一个表格来声明多个变量吗?

时间:2019-04-17 15:29:40

标签: vb.net visual-studio list

我正在创建一个比分锦标赛系统。我创建了一个输入屏幕,用户可以在其中输入一个组的多个分数。当按下提交按钮时,我需要将分数记录到分数中,以便它们可以进入我的排行榜页面上的列表。

下面是我当前的代码。是否可以在用户每次选择提交时刷新表单,但是还可以记录刷新之前的表单结果? 如果没有,我担心我需要为每个小组创建一个新表格。当然不是吗?

Public Class GT_Entry
    Dim Activityscore1 As Integer
    Dim Activityscore2 As Integer
    Dim Activityscore3 As Integer
    Dim Activityscore4 As Integer
    Dim Activityscore5 As Integer
    Dim Groupname As String
    Private Sub Submit_Click(sender As System.Object, e As System.EventArgs) Handles Submit.Click
        Activityscore1 = R1S.Text
        Activityscore2 = R2S.Text
        Activityscore3 = R3S.Text
        Activityscore4 = R4S.Text
        Activityscore5 = R5S.Text
        Groupname = GN.Text
        GN.Clear()
        R1S.Clear()
        R2S.Clear()
        R3S.Clear()
        R4S.Clear()
        R5S.Clear()
    End Sub

1 个答案:

答案 0 :(得分:2)

有几种方法可以解决您的问题。我做了一个类来存储数据。然后创建该类的列表。每次用户单击“提交”,数据都会添加到列表中。您可以迭代列表并访问属性。

Private ScoreList As New List(Of GroupActivityScore)

Private Sub Submit_Click(sender As System.Object, e As System.EventArgs) Handles Submit.Click
    Dim GAS As New GroupActivityScore
    GAS.Score1 = CInt(R1S.Text)
    GAS.Score2 = CInt(R2S.Text)
    GAS.Score3 = CInt(R3S.Text)
    GAS.Score4 = CInt(R4S.Text)
    GAS.Score5 = CInt(R5S.Text)
    GAS.GroupName = GN.Text
    ScoreList.Add(GAS)
    GN.Clear()
    R1S.Clear()
    R2S.Clear()
    R3S.Clear()
    R4S.Clear()
    R5S.Clear()
End Sub

Public Class GroupActivityScore
    Public Property Score1 As Integer
    Public Property Score2 As Integer
    Public Property Score3 As Integer
    Public Property Score4 As Integer
    Public Property Score5 As Integer
    Public Property GroupName As String
End Class