将测试分数存储并写入与其他用户的分数并存储在变量中的文本文件。如何在关闭程序后保持价值? VB.net
该计划内是一个评分表格,显示该进度表格中该用户所有测试的分数。它在我完成测试后正常工作,但是当我注销并关闭程序时,它会在标签中返回到0。
但是,当我关闭程序然后重新运行该程序时,值会更改回0,而不是写入文本文件的实际测试分数。
我该怎么做,以便在我为该用户运行程序时保持相同的值?
末子模块创建存储公共变量Public Topic1Score As Integer
这是从测试本身的代码提取
If answers(i) = questions(i, 4) And FileOpenStatusTS = False Then
Topic1Score += 1
TotalScore += 1
End If
Next
If yearst = "12" And classst = "A" Then
FileOpen(1, FileName12A1, OpenMode.Append)
FileOpenStatus12A1 = True`
一旦所有的细节都被输入并检查,然后将它们写入教师帐户文本文件
WriteLine(1, Username, Topic1Score, TotalScore)
FileClose(1)
End If
这里是读取进度表中的文件。
Private Sub StProgress_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Debug.Assert(Not String.IsNullOrWhiteSpace(Topic1Score))
lblTotalScore.Text = TotalScore
LblTopic2Score.Text = "You scored " & Topic2Score & " out of 5"
lblStName.Text = namest
LblStSurname.Text = surnamest
If yearst = "12" And classst = "A" Then
Dim Filefound As Boolean
Filefound = False
FileOpen(1, FileName12A1, OpenMode.Input)
While Not EOF(1) And Filefound = False
Input(1, Username) 'All the details are read from that account from the 12A1 text file'
Input(1, Topic1Score)
Input(1, TotalScore)
Filefound = True
lblTopic1Score.Text = "You scored " & Topic1Score & " out of 5"
End While
End If
If yearst = "13" And classst = "A" Then
Dim Filefound As Boolean
Filefound = False
FileOpen(1, FileName13A1, OpenMode.Input)
While Not EOF(1) And Filefound = False
Input(1, Username) 'All the details are read from that account from the 12A1 text file'
Input(1, Topic1Score)
Input(1, TotalScore)
Filefound = True
lblTopic1Score.Text = "You scored " & Topic1Score & " out of 5"
End While
End If
If yearst = "12" And classst = "B" Then
Dim Filefound As Boolean
Filefound = False
FileOpen(1, FileName12B1, OpenMode.Input)
While Not EOF(1) And Filefound = False
Input(1, Username) 'All the details are read from that account from the 12A1 text file'
Input(1, Topic1Score)
Input(1, TotalScore)
Filefound = True
lblTopic1Score.Text = "You scored " & Topic1Score & " out of 5"
End While
End If
If yearst = "13" And classst = "B" Then
Dim Filefound As Boolean
Filefound = False
FileOpen(1, FileName13B1, OpenMode.Input)
While Not EOF(1) And Filefound = False
Input(1, Username) 'All the details are read from that account from the 12A1 text file'
Input(1, Topic1Score)
Input(1, TotalScore)
Filefound = True
lblTopic1Score.Text = "You scored " & Topic1Score & " out of 5"
End While
End If
End Sub`
最新代码...测试内 代码... `FileOpenStatusT =假 昏暗的FileFound由于布尔 的FileFound =假 的FileOpen(1,Filenamet,OpenMode.Input) 尽管不EOF(1 )和的FileFound =假 输入(1名) 输入(1 '所有的细节都从TeacherAccounts文本文件阅读该帐户',密码) 输入(1,namet) 输入(1,surnamet)
If Username = TxtUsername.Text And Password = TxtPassword.Text Then 'If the username and account entered are valid then the user is navigated to the TeacherMenu form'
Filefound = True
t = Username
End If
End While
If Filefound = False Then
MsgBox("Username and Password were not a match,please try again")
Else
TeacherMenu.Show()
Me.Hide()
End If`
进展形式码... 如果yearst = “12” 和classst = “A” 然后 昏暗的FileFound由于布尔 的FileFound =假 的FileOpen(1,FileName12A1,OpenMode.Input) 尽管不EOF(1 )和Filefound = False
Input(1, Username) 'All the details are read from that account from the 12A1 text file'
Input(1, Topic1Score)
Input(1, TotalScore)
Filefound = True
If Username = t Then
lblTopic1Score.Text = "You scored " & Topic1Score & " out of 5"
End If
t是一个字符串,并设置为模块中的公共变量。
请向我们显示您的代码。没有办法猜测发生了什么。 –
我已重新编辑代码 – user3167227
内容阅读的代码是相同的 - 我建议您更改“case”或“if”中的文件名,但使用相同的阅读代码。 – evenro