分数未正确计算

时间:2016-02-26 13:15:25

标签: vb.net

您好我为项目创建了一个程序,我现在开始运行一些测试,并且用户的得分没有正确计算,我相信它不能比较给出正确答案的答案。我非常困惑,需要任何帮助。我的代码看起来像这样,任何令人困惑的部分,我都会尝试解释。

Imports System.IO

Public Class QuestionScreen

Dim score As Integer = 0
Dim count As Integer
Dim Difficulty_ext As String
Dim questions, answers As New List(Of String)()
Private i As Integer

Sub ReadFile()

    If Main.Diff_DDown.Text = "Easy" Then
        Difficulty_ext = "questions - Easy"
    ElseIf Main.Diff_DDown.Text = "Medium" Then
        Difficulty_ext = "questions - Medium"
    Else
        Difficulty_ext = "questions - Difficult"
    End If

    Randomize()
    Dim countline = File.ReadAllLines("c:\Users\Alice\Desktop\programme files\" & Difficulty_ext & ".txt").Length
    Dim numline As Integer
    Dim values() As String

    Using sr As New StreamReader("c:\Users\Alice\Desktop\programme files\" & Difficulty_ext & ".txt")
        While Not sr.EndOfStream
            values = sr.ReadLine().Split(","c)
            questions.Add(values(0))
            answers.Add(values(1))
        End While
    End Using

    numline = Int(Rnd() * countline)
    For i As Integer = 0 To numline
        Question.Text = questions(i)
        Act_ANS.Text = answers(i)
    Next
End Sub

Private Sub Pass_Btn_Click(sender As Object, e As EventArgs) Handles Pass_Btn.Click
    If count < 10 Then
        Call ReadFile()
        count = count + 1
        Ans_TxtBx.Text = ""
        Hid_Score.Text = score
    Else
        ResultsScreen.Show()
        Me.Hide()
    End If
End Sub

Public Sub Submit_Btn_Click(sender As Object, e As EventArgs) Handles Submit_Btn.Click
    If count < 10 Then
        Call ReadFile()
        count = count + 1
        If Ans_TxtBx.Text = answers(i) Then

            score = score + 1
        End If
        Hid_Score.Text = score
    Else
        ResultsScreen.Show()
        Me.Hide()
        count = 0
    End If
    Ans_TxtBx.Text = ""
End Sub

Private Sub QuestionScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Call ReadFile()
End Sub
End Class

1 个答案:

答案 0 :(得分:0)

好的.....试试这个,我已经调试了你的代码试图离开它,就像你拥有它一样,有很多问题,没有什么重要的只是几行代码在错误的地方...... 。

Imports System.IO

Public Class Form1

Dim score As Integer = 0
Dim count As Integer
Dim Difficulty_ext As String
Dim questions, answers As New List(Of String)()
Private i As Integer

Sub ReadFile()

    If Diff_DDown.Text = "Easy" Then
        Difficulty_ext = "questions - Easy"
    ElseIf Diff_DDown.Text = "Medium" Then
        Difficulty_ext = "questions - Medium"
    Else
        Difficulty_ext = "questions - Difficult"
    End If

    Randomize()
    Try

        Dim countline = File.ReadAllLines("c:\Users\Alice\Desktop\programme files\" & Difficulty_ext & ".txt").Length
        Dim numline As Integer
        Dim values() As String

        ' clear the list of questions and answers
        answers.Clear()
        questions.Clear()
        '''''''''''''''''''''''''''''''''''''''''

        Using sr As New StreamReader("c:\Users\Alice\Desktop\programme files\" & Difficulty_ext & ".txt")
            While Not sr.EndOfStream
                values = sr.ReadLine().Split(","c)
                questions.Add(values(0))
                answers.Add(values(1))
            End While
        End Using

        numline = Int(Rnd() * countline)
        For i = 0 To numline
            Question.Text = questions(i)
            Act_ANS.Text = answers(i)
        Next
    Catch ex As Exception

    End Try
End Sub

Private Sub Pass_Btn_Click(sender As Object, e As EventArgs) Handles Pass_Btn.Click
    If count < 10 Then
        count = count + 1
        Ans_TxtBx.Text = ""
        Hid_Score.Text = score
    Else
        ResultsScreen.Show()
        Me.Hide()
    End If
    Call ReadFile() '  move this to the bottom
End Sub

Public Sub Submit_Btn_Click(sender As Object, e As EventArgs) Handles Submit_Btn.Click
    If count < 10 Then
        count = count + 1
        If Ans_TxtBx.Text = answers(i - 1) Then ' need to subtract 1 here

            score = score + 1
        End If
        Hid_Score.Text = score
    Else
        ResultsScreen.Show()
        Me.Hide()
        count = 0
    End If
    Ans_TxtBx.Text = ""
    Call ReadFile() '  move this to the bottom
End Sub

Private Sub QuestionScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Call ReadFile()
End Sub

End Class