如何让标签显示标签中测试的当前用户分数?

时间:2014-04-03 23:33:37

标签: vb.net winforms

我创建了一个测试系统,该系统应该显示标签中的分数,但是在运行时标签保留为“测试尚未完成”的默认设置文本

变量t在模块Public t As String

中公开创建

这是用户登录时的代码,变量t设置为当前用户的用户名。

FileOpenStatusst = False
Dim Filefound As Boolean
Filefound = False
FileOpen(1, FileNamest, OpenMode.Input)
While Not EOF(1) And Filefound = False
  Input(1, Username)
  Input(1, Password)
  Input(1, namest)
  Input(1, surnamest)
  Input(1, classst)
  Input(1, yearst)
  If Username = TxtUsername.Text And Password = TxtPassword.Text Then
    Filefound = True
    t = Username
  End If
End While
If Filefound = False Then
  MsgBox("Username and Password were not a match,please try again")
Else
  StudentMenu.Show()
  Me.Hide()
End If
FileClose(1)

这是进度屏幕的代码,用于在标签

中显示测试分数
Private Sub StProgress_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
  Debug.Assert(Not String.IsNullOrWhiteSpace(Topic1Score))
  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
      If Username = t Then
        lblTopic1Score.Text = "You scored " & Topic1Score & " out of 5"
      End If
      FileClose()
      Dim Filefound2 As Boolean
      Filefound2 = False
      FileOpen(1, FileNameTotalScores, OpenMode.Input)
      While Not EOF(1) And Filefound2 = False
        Input(1, Username) 'All the details are read from that account from the 12A1 text file'
        Input(1, TotalScore)
        Filefound = True
        If Username = t Then
          lblTotalScore.Text = "Your current Total Score is " & TotalScore
        End If
      End While
    End While
  End If

以下是用户完成测试时的代码,然后将分数加起来然后存储。

FILECLOSE(1)         FileOpenStatusTS = False

    For i = 0 To 4

        If answers(i) = questions(i, 4) And FileOpenStatusTS = False Then

            Topic1Score += 1
            TotalScore += 1
            TestsCompleted += 1
            Attempts += 1



        End If

    Next
    Topic1Score.ToString()
    If yearst = "12" And classst = "A" Then
        FileOpen(1, FileName12A1, OpenMode.Append)
        FileOpenStatus12A1 = True

        'Once all the details have been entered and checked, then they are written to the Teacher accounts text file'
        WriteLine(1, Username, Topic1Score, Attempts)
        FileClose(1)
    End If

1 个答案:

答案 0 :(得分:0)

您的问题在于您将3个变量写入文件,只读取2个。

运行时间无法猜测路上还有另一个变量。

添加

Input(1, Topic1Score)

在已经存在的两个输入之间的while循环中(或者如果我没有正确地找出格式,则在相关位置)..

它看起来应该是这样的:

  While Not EOF(1) And Filefound2 = 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
      lblTotalScore.Text = "Your current Total Score is " & TotalScore
    End If
  End While

每条记录的文件格式相同 - 因此您需要以与第一条记录及其余记录相同的方式阅读。


请分开循环(你使用相同的文件ID,所以读取是"困惑"):

 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
      If Username = t Then
        lblTopic1Score.Text = "You scored " & Topic1Score & " out of 5"
      End If
    End While

    FileClose()
    Dim Filefound2 As Boolean
    Filefound2 = False
    FileOpen(1, FileNameTotalScores, OpenMode.Input)
    While Not EOF(1) And Filefound2 = False
      Input(1, Username) 'All the details are read from that account from the 12A1 text file'
      Input(1, TotalScore)
      Filefound = True
      If Username = t Then
        lblTotalScore.Text = "Your current Total Score is " & TotalScore
      End If
    End While
  End If