vb.net - 我可以重复使用表单来声明多个变量吗?
问题描述
我正在创建一个分数锦标赛系统。我创建了一个输入屏幕,用户可以在其中输入一个组的多个分数。当按下提交按钮时,我需要记录分数到分数,以便它们可以进入我的排行榜页面上的列表。
以下是我当前的代码。是否可以在用户每次选择提交时刷新表单,但也可以记录刷新之前表单的结果?如果没有,我担心我需要为每个组创建一个新表单。确定不是这样吗?
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
解决方案
有几种方法可以解决您的问题。我做了一个类来存储数据。然后创建了该类的列表。每次用户单击提交时,数据都会添加到列表中。您可以迭代列表并访问属性。
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
推荐阅读
- python - 如何遍历字典列表并打印特定键的值?
- angularjs - .then 中的期望条件不会执行
- performance - 基准测试 - 如何计算发送到 CPU 的指令数以查找消耗的 MIPS
- php - php在没有相对路径的绝对url中转换包含相对路径的绝对url
- azure - 在 Azure 上设置 Jenkins、Docker、Kubernetes ci/cd
- javascript - 在javascript中比较两个相同的字符串失败
- sql - 查询将比递归 cte 执行得更好
- php - 在变量中添加 wp_insert_post() 重要吗?
- react-native - React Native fetch 在发布 multipart/form-data 时抛出错误
- jquery - 单击与 div 的内部按钮冲突的 slideToggle div