Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz)
Streamreader - random lines (quiz) Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
Go Back  Xtreme Visual Basic Talk > > > Streamreader - random lines (quiz)


Reply
 
Thread Tools Display Modes
  #1  
Old 03-12-2015, 03:14 AM
alien8k alien8k is offline
Newcomer
 
Join Date: Mar 2015
Posts: 3
Default 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
Reply With Quote
  #2  
Old 03-15-2015, 09:35 AM
PeetSoft's Avatar
PeetSoft PeetSoft is offline
Centurion
 
Join Date: Jun 2003
Location: HHW - the Netherlands
Posts: 184
Default

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
__________________
-----------------------------------------------------
If debugging is the art of removing bugs, then
programming must be the art of inserting them.
I do comply with Flyguy's signature (If he still had one)
Reply With Quote
  #3  
Old 04-12-2015, 12:51 PM
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 12:57 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
Streamreader - random lines (quiz) Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz) Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
 
Streamreader - random lines (quiz)
Streamreader - random lines (quiz)
 
-->