How to Create a Local Revision Tool in Visual Basic

Language

Introduction: Welcome to my tutorial on how to create a Revision Tool program in Visual Basic. Steps of Creation: Step 1: First we need to create a form with... button1 - add a new question and answer textbox1 - contain a new question textbox2 - contain a new answer textbox3 - contain answer to current question button2 - begin revision button3 - check answer label1 - contain current question. We also want to create a few variables, they are all self explanatory.
  1. Dim question As New List(Of String)
  2. Dim answers As New List(Of String)
  3. Dim curPos As Integer = -1
  4. Dim rand As New Random
Step 2: Next we want to create a couple of custom functions. One will simply randomly select the next question to test the user on. The other will check the answer.
  1. Private Function checkAnswer()
  2. If (TextBox3.Text.ToLower() = answers(curPos).ToLower()) Then
  3. MsgBox("Correct!")
  4. Else : MsgBox("Wrong! The right answer is: " & answers(curPos))
  5. End If
  6. End Function
  7. Private Function setNewQuestion()
  8. Dim r As Integer = curPos
  9. Do Until Not r = curPos
  10. r = rand.next(question.Count())
  11. Loop
  12. curPos = r
  13. Label1.Text = question(curPos)
  14. End Function
Step 3: For the button1 click event action we want to add the new question and answer to our lists...
  1. question.Add(TextBox1.Text)
  2. answers.Add(TextBox2.Text)
Step 4: The button1 click event action will begin the revision which will lock our add new question and answer controls and select the first question using our custom function setNewQuestion.
  1. If (question.Count() > 0) Then
  2. TextBox1.Enabled = False
  3. TextBox2.Enabled = False
  4. TextBox3.Enabled = True
  5. Button3.Enabled = True
  6. Button1.Enabled = False
  7. Button2.Enabled = False
  8. setNewQuestion()
  9. End If
Step 5: Finally, the button3 click event action will check the given answer to the current question and select a new question to test next.
  1. checkAnswer()
  2. setNewQuestion()
Project Complete! Below is the full source code and download to the project files.
  1. Public Class Form1
  2. Dim question As New List(Of String)
  3. Dim answers As New List(Of String)
  4. Dim curPos As Integer = -1
  5. Dim rand As New Random
  6. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  7. question.Add(TextBox1.Text)
  8. answers.Add(TextBox2.Text)
  9. End Sub
  10. Private Function checkAnswer()
  11. If (TextBox3.Text.ToLower() = answers(curPos).ToLower()) Then
  12. MsgBox("Correct!")
  13. Else : MsgBox("Wrong! The right answer is: " & answers(curPos))
  14. End If
  15. End Function
  16. Private Function setNewQuestion()
  17. Dim r As Integer = curPos
  18. Do Until Not r = curPos
  19. r = rand.next(question.Count())
  20. Loop
  21. curPos = r
  22. Label1.Text = question(curPos)
  23. End Function
  24.  
  25. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  26. If (question.Count() > 0) Then
  27. TextBox1.Enabled = False
  28. TextBox2.Enabled = False
  29. TextBox3.Enabled = True
  30. Button3.Enabled = True
  31. Button1.Enabled = False
  32. Button2.Enabled = False
  33. setNewQuestion()
  34. End If
  35. End Sub
  36.  
  37. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  38. checkAnswer()
  39. setNewQuestion()
  40. End Sub
  41. 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.

Add new comment