first i want apologize for my english, but i hope u will undestand me.
I have problem with me quiz program. Generating random 10questions (after 10 random Questions -> end) from txt without repeating, i sent u code, its work great, but questions are repeated.
I have menu form where is start button, which will jump to form1 where is testing.. after 10 quesiton will show msgbox with result and jump back to menu.., testing form will hide as u can see. And every time when i start quiz i need every question just once.
I dont know how fix it. May u help me please?
My txt file:
Question|Answer1|Answer2|Answer3|rightanswer(a/b/c)
example:
The capitol city of England is?|Prague|Sidney|New York|b
this is syntax of my txt file.
And i have this code:
Expand|Select|Wrap|Line Numbers
- Public Class Form1
- Dim q1(10), a1(10), a2(10), a3(10), ca(10) As String ' load questions , answers & correct answer
- Dim value As Integer = 0
- Dim counter As Integer = 0
- Dim x As Integer 'result
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Label3.Text = Label3.Text + 1
- Dim selectedanswer As String = ""
- If RadioButton1.Checked = True Then selectedanswer = "a"
- If RadioButton2.Checked = True Then selectedanswer = "b"
- If RadioButton3.Checked = True Then selectedanswer = "c"
- If selectedanswer = ca(value) Then x = x + 1
- RadioButton1.Checked = False
- RadioButton2.Checked = False
- RadioButton3.Checked = False
- If Label3.Text = 10 Then
- MsgBox("Your Result is " & x)
- Form2.Show()
- me.hide()
- End If
- loadquestions()
- End Sub
- Public Sub loadquestions()
- ' Initialize the random-number generator.
- Randomize()
- ' Generate random value between 1 and 10.
- value = CInt(Int(((counter - 1) * Rnd()) + 1))
- Label1.Text = q1(value).ToString
- RadioButton1.Text = a1(value).ToString
- RadioButton2.Text = a2(value).ToString
- RadioButton3.Text = a3(value).ToString
- End Sub
- Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- OpenFileDialog1.ShowDialog()
- Dim soubor As New IO.StreamReader(OpenFileDialog1.FileName)
- While Not soubor.EndOfStream
- Dim txtline() As String = soubor.ReadLine().Split("|")
- q1(counter) = txtline(0)
- a1(counter) = txtline(1)
- a2(counter) = txtline(2)
- a3(counter) = txtline(3)
- ca(counter) = txtline(4)
- counter = counter + 1
- End While
- loadquestions()
- End Sub
- End Class