Hello everyone!
I would like to create a quiz and wonder what is the best way.
1. Using a textfile to read in the questions/answer
2. Using radio buttons
3. Or something else you suggest?

Ps: I have lot of questions in the quiz

Thank you

I would consider an XML format.

<?xml version="1.0" encoding="utf-8"?>
		<QuestionText>What date was time travel invented?</QuestionText>
		<Answer>July 4, 1776</Answer>
		<Answer>December 7, 1941</Answer>
		<Answer>August 16, 1977</Answer>
		<Answer Correct="true">November 5, 1955</Answer>
		<QuestionText>How much power is required for the flux capacitor to work?</QuestionText>
		<Answer>4 Palpatines</Answer>
		<Answer>3 Vaders</Answer>
		<Answer Correct="true">1.21 Gigawatts</Answer>

You can use XML deserialization or LINQ to XML to easily read the data into an appropriate structure and then use it to control the quiz interface.

[Editing in a usage example]

Based on the aforementioned schema, here is a usage example (LINQ to XML):

Imports System.Linq
Imports System.Xml.Linq

Module Module1

    Sub Main()

        Dim xmlFile As String = "C:\Temp\quiz.xml"
        Dim document As XDocument = XDocument.Load(xmlFile)

        Dim query = From question In document.Descendants("Question") _
                    Select New With _
                    { _
                        .QuestionText = question.Element("QuestionText").Value, _
                        .Answers = (From answer In question.Descendants("Answer") _
                                   Select New With _
                                   { _
                                    .AnswerText = answer.Value, _
                                    .AnswerCorrect = If(answer.Attribute("Correct") Is Nothing, False, Boolean.Parse(answer.Attribute("Correct").Value)) _
                                    }).ToList() _

        For Each question In query
            For Each answer In question.Answers
                Console.WriteLine("{0}{1}{2}", answer.AnswerCorrect, vbTab, answer.AnswerText)


    End Sub

End Module
using System;
using System.Linq;
using System.Xml.Linq;

class Program
    static void Main(string[] args)
        string xmlFile = @"C:\Temp\quiz.xml";
        XDocument document = XDocument.Load(xmlFile);

        var query = from question in document.Descendants("Question")
                    select new
                        QuestionText = question.Element("QuestionText").Value,
                        Answers = (from answer in question.Descendants("Answer")
                                   select new
                                       AnswerText = answer.Value,
                                       AnswerCorrect = answer.Attribute("Correct") != null ? bool.Parse(answer.Attribute("Correct").Value) : false

        foreach (var question in query)
            foreach (var answer in question.Answers)
                Console.WriteLine("{0}\t{1}", answer.AnswerCorrect, answer.AnswerText);



And the output in the console:

What date was time travel invented?
False   July 4, 1776
False   December 7, 1941
False   August 16, 1977
True    November 5, 1955

How much power is required for the flux capacitor to work?
False   4 Palpatines
False   3 Vaders
True    1.21 Gigawatts

Edited 6 Years Ago by apegram: n/a


thank you, that's a good idea. unfortunately i am not familar at all with zml. but thanks anyway

This article has been dead for over six months. Start a new discussion instead.