Reputation: 31
So since I have put that a variable, even though it says that i=3, it doesn't go on with the questions and I really don't know what else to do, the i goes up but the questions don't.. I know I may be very bad at this but why untill 5 seconds ago it worked, now it doesn't.
Public Class Test1
Dim question(3, 5) As String
Dim i As Integer = 2
Dim correctanswear = 0
Dim a As Integer = 0
Private Sub Test1_Load()
question(1, 0) = "2+2="
question(1, 1) = "1"
question(1, 2) = "2"
question(1, 3) = "3"
question(1, 4) = "4"
question(2, 0) = "How old are you?"
question(2, 1) = "12"
question(2, 2) = "13"
question(2, 3) = "18"
question(2, 4) = "17"
question(3, 0) = "7+14="
question(3, 1) = "23"
question(3, 2) = "21"
question(3, 3) = "34"
question(3, 4) = "22"
Label1.Text = question(i - 1, 0)
nr1.Text = question(i - 1, 1)
nr2.Text = question(i - 1, 2)
nr3.Text = question(i - 1, 3)
nr4.Text = question(i - 1, 4)
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Test1_Load()
Button5.Hide()
Button2.Visible = "True"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Hide()
MainMenu.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If a > 3 Then
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
Else
If i = 2 AndAlso nr4.Checked = True Then
correctanswear += 1
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
i = i + 1
MessageBox.Show(i)
ElseIf i = 3 AndAlso nr3.Checked Then
correctanswear += 1
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
i = i + 1
MessageBox.Show(i)
End If
If i = 4 AndAlso nr2.Checked = True Then
MessageBox.Show(i)
correctanswear += 1
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
Button2.Hide()
Button5.Text = "Retake the test"
Button5.Show()
End If
End If
a = a + 1
End Sub
End Class
Upvotes: 0
Views: 36
Reputation: 9193
Whenever a user enters a correct answer you must call Test1_Load
so that the question updates.
Example:
If i = 2 AndAlso nr4.Checked = True Then
correctanswear += 1
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
i = i + 1
MessageBox.Show(i)
Test1_Load()
ElseIf i = 3 AndAlso nr3.Checked Then
correctanswear += 1
MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
i = i + 1
MessageBox.Show(i)
Test1_Load()
End If
On another note, it would probably be worth breaking the question updating code out into its own function (called by Test1_Load
and when user gets a correct answer) so that you don't have to re-initialize the array of questions multiple times per test.
Upvotes: 1