-1

I'm working on a project where I display questions in Textboxes. Underneath each one of them there are 4 checkboxes and the user has to select the one that answers to the question.

Is there any way I can just put all my questions, answers, etc in a .txt file and load them from there? I don't want to have have to write a case for each and every question(I have 120 questions approximately).

My way of doing it so far:

    case 5: // Multiple Answers
                txtQuestion.Text = "What are the characteristics of the " +
                                   "Main method? (Choose two)";

                grpSingleChoice.Visible = false;
                grpMultipleChoice.Visible = true;

                chkAnswer1.Text = "A. It must always return void";
                chkAnswer2.Text = "B. It is always the first method inside the " +
                                  "main class of a program";
                chkAnswer3.Text = "C. It is the start and end point of a program";
                chkAnswer4.Text = "D. It must always be passed an array of strings " +
                                  "as in static void Main(string[] args)";
                chkAnswer5.Visible = true;
                chkAnswer5.Text = "E. It must be created inside of a class" +
                                  "or a structure";
                break;
gabsferreira
  • 3,089
  • 7
  • 37
  • 61
RawMeat
  • 1
  • 4
  • 2
    Even better: use a database ;) – Tim Schmelter May 09 '14 at 16:00
  • Yes there are - have a go and let us know a specific question because at the moment its too broad a question to answer. There are too many possible solution.s – Ian May 09 '14 at 16:01
  • You might consider an XML file, also. You can have "Question" elements and "Answer" elements. – 001 May 09 '14 at 16:03
  • For this I can't use a database it's not allowed. The person requested specifically not to use a database (don't know why he wouldn't cause it's much better but hey !). I'm actually looking to put the q & a & possible comment in just a textfile. is that possible? – RawMeat May 09 '14 at 16:06
  • Many, many ways to do this. If you can fit each question and each answer on one line a low-fi way would be to prefix each question with a 'Q', then add those answers and finally one line witha solution, maybe 'SB' for 'B'; then read from Q to S process and repeat.. For processing you would use the substrings line.SubString(0,1) and line.SubString(1).. – TaW May 09 '14 at 16:07
  • 2
    Use XML if you can't use a database – Jonesopolis May 09 '14 at 16:07
  • Not really formilliar with that , how would that work? – RawMeat May 09 '14 at 16:11

1 Answers1

1

A simple way of doing this can be:

[START]
Question = Imagine you write code and include a backslash in a string, the compiler ...
Correct = 2
Option = Answer a
Option = Answer b
Option = Answer c
Option = Answer d
[END]

The "tags" will be your loop conditions, so just use Split(lineText, " = ") to get the values. But XML is much better solution :

<xml>
    <question correct="2">
        <description>Imagine you write code and include a backslash in a string, the compiler ....</description>
        <option>answer</option>
        <option>answer</option>
        <option>answer</option>
        <option>answer</option>
    </question>
    <question correct="3">
        <description>Another question....</description>
        <option>answer</option>
        <option>answer</option>
        <option>answer</option>
        <option>answer</option>
    </question> 
</xml>
JotaSantana
  • 33
  • 1
  • 6