Dim question As New List(Of String) Dim answers As New List(Of String) Dim curPos As Integer = -1 Dim rand As New Random
Private Function checkAnswer() If (TextBox3.Text.ToLower() = answers(curPos).ToLower()) Then MsgBox("Correct!") Else : MsgBox("Wrong! The right answer is: " & answers(curPos)) End If End Function Private Function setNewQuestion() Dim r As Integer = curPos Do Until Not r = curPos r = rand.next(question.Count()) Loop curPos = r Label1.Text = question(curPos) End Function
question.Add(TextBox1.Text) answers.Add(TextBox2.Text)
If (question.Count() > 0) Then TextBox1.Enabled = False TextBox2.Enabled = False TextBox3.Enabled = True Button3.Enabled = True Button1.Enabled = False Button2.Enabled = False setNewQuestion() End If
checkAnswer() setNewQuestion()
Public Class Form1 Dim question As New List(Of String) Dim answers As New List(Of String) Dim curPos As Integer = -1 Dim rand As New Random Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click question.Add(TextBox1.Text) answers.Add(TextBox2.Text) End Sub Private Function checkAnswer() If (TextBox3.Text.ToLower() = answers(curPos).ToLower()) Then MsgBox("Correct!") Else : MsgBox("Wrong! The right answer is: " & answers(curPos)) End If End Function Private Function setNewQuestion() Dim r As Integer = curPos Do Until Not r = curPos r = rand.next(question.Count()) Loop curPos = r Label1.Text = question(curPos) End Function Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If (question.Count() > 0) Then TextBox1.Enabled = False TextBox2.Enabled = False TextBox3.Enabled = True Button3.Enabled = True Button1.Enabled = False Button2.Enabled = False setNewQuestion() End If End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click checkAnswer() setNewQuestion() End Sub End Class
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.