如何让标签显示当前用户在标签中的测试分数? [英] How do I get the Labels to display the current user's scores from the tests in the labels?

查看:33
本文介绍了如何让标签显示当前用户在标签中的测试分数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a Test system that is supposed to show the scores in the labels, however when run the labels stay as the default set text of "Test Not yet completed"

变量 t 在模块中被创建为 public Public t As String

The variable t is created public in a module Public t As String

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

This is the code when the user logs in and the variable t is set to the username of the current user.

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)

这是进度屏幕的代码,用于在标签中显示测试分数

This is the code for the Progress Screen to show the Test Score in the label

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

这是用户完成测试并将分数相加然后存储的代码.

Here is the code for the when the user completes the test and the score is added up then stored.

文件关闭(1)FileOpenStatusTS = False

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

推荐答案

你的问题是你将 3 个变量写入文件,而只读取了两个.

You're problem is that you're writing 3 variables to the file, and reading only two.

运行时无法猜测途中还有另一个变量.

The run time cannot guess that there's another variable on the way.

添加

Input(1, Topic1Score)

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

in the while loop between the two inputs that are already there (or in the relevant place if I did not figure out the format correctly)..

它应该是这样的:

  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

每条记录的文件格式都相同 - 因此您需要以相同的方式读取第一条记录和其余记录.

The file format is the same for each record - so you need to read the same way the first record, and the rest of them.

也请分开循环(您使用相同的文件 ID,因此读取会混淆"):

Please separate the loops too (you use the same file ID, so the reads are "confused"):

 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

这篇关于如何让标签显示当前用户在标签中的测试分数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆