How to Create a Local Revision Tool in Visual Basic
Submitted by Yorkiebar on Tuesday, October 15, 2013 - 08:38.
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.
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.
Step 3:
For the button1 click event action we want to add the new question and answer to our lists...
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.
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.
Project Complete!
Below is the full source code and download to the project files.
- 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.
Add new comment
- 64 views