Save two text files

hendrikbez

Active member
Joined
Nov 24, 2005
Messages
35
Location
South Afica
Programming Experience
1-3
I have two text boxes that I put in.
textbox 1 I type in clue
textbox 2 I type in answer.

This is my code.

VB.NET:
 Private Sub BtnCodes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCodes.Click

        System.IO.File.AppendAllText("C:\Do_It\clue.txt", Environment.NewLine & txtClue.Text)
        Cls_MessageBbox.Show("Die Luidraad" & Environment.NewLine & txtClue.Text & Environment.NewLine & "is bygevoeg in txtClue.Txt")
        txtClue.Text = ""
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        System.IO.File.AppendAllText("C:\Do_It\answer.txt", Environment.NewLine & txtAnswer.Text)
        Cls_MessageBbox.Show("Die Antwoord" & Environment.NewLine & txtAnswer.Text & Environment.NewLine & "is bygevoeg" & Environment.NewLine & "in Answer.txt", txtAnswer.Text)
        txtAnswer.Text = ""

How can I make it that I can sace boths of them togeter, as a clue must always have an answer, so that when I read the clue it must show the answer to me.

The clue can also have more than one correct anwser, how does that work.
 
Last edited:
There are alot of different ways you could go about this one but I would create a typed dataset with two tables, your questions in the parent table and answer choices per question in the child table (along with a column that indicates which is the correct answer). In the dataset create a relationship between the two tables.

Once your dataset is set up, reading and writing to a file is easy. Dataset.ReadXml(yourFile) or Dataset.WriteXml(yourFile).
 
I dont think it helps for me to write the application for you. There is plenty of information about it here on the boards and within the visual studio help file. However if you do have a more specific question or get stuck and need help, feel free to ask.

Again start with looking up datasets. You can create tables within the dataset, fill in your questions & answer choices and with a single command can read & write all the info to a single file.

VB.NET:
<tblQuestions>
           <QuestionId>1</QuestionId> 
           <Question>What color is the sky?</Question> 
                 <tblAnswerChoices>
                           <AnswerId>-1</AnswerId> 
                           <QuestionId>1</QuestionId> 
                           <Choice>Red</Choice> 
                           <Answer>false</Answer> 
                  </tblAnswerChoices>
                  <tblAnswerChoices>
                           <AnswerId>-2</AnswerId> 
                           <QuestionId>1</QuestionId> 
                           <Choice>White</Choice> 
                           <Answer>false</Answer> 
                   </tblAnswerChoices>
                   <tblAnswerChoices>
                           <AnswerId>-3</AnswerId> 
                           <QuestionId>1</QuestionId> 
                           <Choice>Blue</Choice> 
                           <Answer>true</Answer> 
                     </tblAnswerChoices>
 </tblQuestions>
 
Back
Top