我正在研究一个大学项目,在这个项目中我必须创建一个程序,它存储了20个问题和答案,然后一个接一个地显示在一个教师窗体上(点击下一个按钮)放在学生表格上。VB.net中的数组混淆
我遇到的问题是我可以输入问题和答案(数组0到19),但是当学生回答问题时,只显示19个问题,而最后一个问题没有出现。
让我知道我可以告诉你什么来帮助解决我的问题。
Module Module1
Public myQ(0 To 19) As String
Public myA(0 To 19) As String
End Module
Public Class frmTeacher
Public myCounter As Integer
Private Sub frmTeacher_Load(sender As Object, e As EventArgs) Handles MyBase.Load
myCounter = (0)
End Sub
Private Sub btnTeacherNext_Click(sender As Object, e As EventArgs) Handles btnTeacherNext.Click
If myCounter < 19 Then
myQ(myCounter) = txtTeacherQ.Text
myA(myCounter) = txtTeacherA.Text
myCounter = myCounter + 1
txtTeacherQ.Text = ""
txtTeacherA.Text = ""
Else
MsgBox("20 Questions Created, Moving on To Student Screen")
Me.Hide()
frmStudent1.Show()
End If
End Sub
Public Class frmStudent1
Dim myScore As Integer
Dim MyCounter2 As Integer
Public myNames As String
Private Sub btnStudentHelp_Click(sender As Object, e As EventArgs) Handles btnStudentHelp.Click
MsgBox("Questions will be shown to the left, Place your answer into the box on the right and click next")
End Sub
Private Sub frmStudent1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lblStudentQ.Text = myQ(0)
HideItAll()
txtStudentName.Visible = True
btnStart.Visible = True
End Sub
Private Sub HideItAll()
lblStudentQ.Visible = False
txtStudentA.Visible = False
txtStudentName.Visible = False
btnStudentHelp.Visible = False
btnNextStudent.Visible = False
btnStart.Visible = False
btnStudentNext.Visible = False
End Sub
Private Sub btnStudentNext_Click(sender As Object, e As EventArgs) Handles btnStudentNext.Click
If MyCounter2 < 19 Then
If txtStudentA.Text = myA(MyCounter2) Then
myScore = myScore + 1
End If
MyCounter2 = MyCounter2 + 1
lblStudentQ.Text = myQ(MyCounter2)
Else
MsgBox("Your score is " + Str(myScore))
myNames = myNames + txtStudentName.Text + ": " + Str(myScore) + vbNewLine
HideItAll()
btnNextStudent.Visible = True
End If
End Sub
Private Sub btnNextStudent_Click(sender As Object, e As EventArgs) Handles btnNextStudent.Click
Me.Refresh()
HideItAll()
txtStudentName.Visible = True
btnStart.Visible = True
End Sub
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
myScore = 0
MyCounter2 = 0
If txtStudentName.Text = "teacher" Then
MsgBox("The scores are as follows: " + vbNewLine + myNames)
End If
HideItAll()
lblStudentQ.Visible = True
txtStudentA.Visible = True
btnStudentHelp.Visible = True
btnStudentNext.Visible = True
End Sub
End Class
你应该补充一点,初始化代码失败该数组和代码显示下一个问题/回答 – Steve
编辑第一篇文章:)将尝试并修复它的格式,虽然 – ConfusedStudent