Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET File I/O and Registry (http://www.xtremevbtalk.com/-net-file-i-o-and-registry/)
-   -   Streamreader - random lines (quiz) (http://www.xtremevbtalk.com/-net-file-i-o-and-registry/327525-streamreader-random-lines-quiz.html)

alien8k 03-12-2015 02:14 AM

Streamreader - random lines (quiz)
 
Hello,
First i want apologize for my english and i hope u will undestand me.
I need create testing (quiz) software. (question and 3 answers)
I have this code now:
Code:

// My txt file with questions and asnwers:
Question1|answer1|answer2|answer3|rightasnwer1
Question2|answer1|answer2|answer3|rightasnwer3
// rightanswer1-3: here is a, b or c, its tell to progam which answer is right. I will create condition with radio button, its no problem i know how to do this

// FORM
Dim soubor As New IO.StreamReader("database.txt")
While Not soubor.EndOfStream
Dim txtline() as string = soubor.readline().split("|") 'split line to aray of string by |
Dim question As string = txtline(0)
Dim answer1 As string = txtline(1)
Dim answer2 As String = txtline(2)
Dim answer3 As String = txtline(3)
Dim rightanswer As String = txtline(4)
End While
 
// Labels
label1.Text = question
label2.Text = answer1
label3.Text = answer2
label4.Text = answer3

I have menu FORM and there is start button. I need to help with code of this button. After click -> open new form and generate random question from txt file, i dont know how to do it.)
And at this new form with generated question and answers.. i need next button which generate again new random question and answers to labels.

Thanks for help. :)
alien8k

PeetSoft 03-15-2015 08:35 AM

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

alien8k 04-12-2015 11:51 AM

Quote:

Originally Posted by PeetSoft (Post 1407947)
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



All times are GMT -6. The time now is 02:25 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.