View Single Post
 
Old 04-12-2015, 11:51 AM
alien8k alien8k is offline
Newcomer
 
Join Date: Mar 2015
Posts: 3
Default

Quote:
Originally Posted by PeetSoft View Post
read the whole textfile; textline=soubor.readtoend()

dim lines() as string = txtfile.split(vbcr)
dim c as integer=textline.count

Randomize()
Dim line As Integer = CInt(Int((c * Rnd()) + 1))

dim ques as string = lines(line)
dim Q() as string=ques.split("|")

dim question as string=Q(0)
dim ans1 as string=Q(1)
dim ans2 as string=Q(2)
dim ans3 as string=Q(3)

form2.label1.text=question
form2.label2.text=ans1
form2.label3.text=ans2
form2.label4.text=ans3
form2.show
I dont know how edit your code, i will change to red color lines, where is error.
At form1 where are labels for Question and answers i should use same to code to button? (this button should generate next random question to lables)
And how i can add to code something what can stop quiz and show new Form with some reviews (10Questions -> then End)
Code:
Public Class Menu

    Private Sub Menu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load // This is first Form named Menu, here is only start button
        Dim soubor As New IO.StreamReader("textfile1.txt")
        While Not soubor.EndOfStream
            Dim txtline() As String = soubor.ReadLine().Split("|")
            Dim question As String = txtline(0)
            Dim ans1 As String = txtline(1)
            Dim ans2 As String = txtline(2)
            Dim ans3 As String = txtline(3)
            Dim rightanswer As String = txtline(4)
        End While
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        read the whole textfile; textline=soubor.readtoend() // i dont know how edit this code, my txt file is named textfile1

        Dim lines() As String = txtfile.split(vbCr)
        Dim c As Integer = textline.count // My VB 2010 said: its not declared "textline.count" and "txtfile.split(vbCr)"

        Randomize()
        Dim line As Integer = CInt(Int((c * Rnd()) + 1))

        Dim ques As String = lines(line)
        Dim Q() As String = ques.Split("|")

        Dim question As String = Q(0)
        Dim ans1 As String = Q(1)
        Dim ans2 As String = Q(2)
        Dim ans3 As String = Q(3)

        Form1.Label1.Text = question
        Form1.Label2.Text = ans1
        Form1.Label3.Text = ans2
        Form1.Label4.Text = ans3
        Form1.Show()
    End Sub
End Class

Last edited by alien8k; 04-12-2015 at 11:57 AM.
Reply With Quote