將測試分數存儲並寫入與其他用戶的分數並存儲在變量中的文本文件。如何在關閉程序後保持價值? 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