I need help writting a Trivia Game for a school project. The teacher wanted us to get used to looking to forums and google for help so he refuses to help us for this particular summative.
What I want to know is...
- how to use a streamreader to read questions randomly from a text document located in the debug folder (I have 10 questions all in 1 text file in the debug folder, and the same for all of my answers)
- how to use a streamreader and split function to read answers from a text document located in the debug folder to a combobox.
My program is set up like this.
I have a forum "Game" with 3 buttons, one for each catagory. When the catagory is selected a second form "Question" loads with a combobox and a lable. In the lable I want to display a question from my text file randomly, then have the corresponding set of answers displayed in the combobox. When the player selectes the right answers they get points.
My current code looks like this, and dosen't work
Private Sub btnDogs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDogs.Click
Dim strDogA As String
Dim strDog() As String
Dim objDogs As New System.IO.StreamReader("Dog_Question.txt")
frmQuestions.lblQuestion.Text = objDogs.ReadLine
strDogA = "Dog_Answer.txt"
strDog = strDogA.Split("/")
frmQuestions.cmbAnswers.Items.Add(strDog)
frmQuestions.Visible = True
Me.Visible = False
I know that .ReadLine is only to read the first line of text in a text document and thats why it's not reading the questions properly, I only put it as that because I don't know how to code it so that it will read a random 1 of 10 questions from a text document, and needed to have it read something just to test it.
Just so that you know, this is how my questions and answers are set up.
Questions - All of my questions for each catagory are in 1 text file like this
Question 1
Question 2
Question 3
Answers - I have it set up like multiple choice so my answers are all in 1 text file like my questions but each option is separated by / like this.
right answer/wrong answer/wrong answer
wrong answer/ right asnwer/ wrong answer
I appologize if what I am asking is confusing, I know that the way I have things organized and worded can be a bit confusing, I was just trying to include everything so that you would know exactly what I am trying to do with the code.
What I want to know is...
- how to use a streamreader to read questions randomly from a text document located in the debug folder (I have 10 questions all in 1 text file in the debug folder, and the same for all of my answers)
- how to use a streamreader and split function to read answers from a text document located in the debug folder to a combobox.
My program is set up like this.
I have a forum "Game" with 3 buttons, one for each catagory. When the catagory is selected a second form "Question" loads with a combobox and a lable. In the lable I want to display a question from my text file randomly, then have the corresponding set of answers displayed in the combobox. When the player selectes the right answers they get points.
My current code looks like this, and dosen't work
Private Sub btnDogs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDogs.Click
Dim strDogA As String
Dim strDog() As String
Dim objDogs As New System.IO.StreamReader("Dog_Question.txt")
frmQuestions.lblQuestion.Text = objDogs.ReadLine
strDogA = "Dog_Answer.txt"
strDog = strDogA.Split("/")
frmQuestions.cmbAnswers.Items.Add(strDog)
frmQuestions.Visible = True
Me.Visible = False
I know that .ReadLine is only to read the first line of text in a text document and thats why it's not reading the questions properly, I only put it as that because I don't know how to code it so that it will read a random 1 of 10 questions from a text document, and needed to have it read something just to test it.
Just so that you know, this is how my questions and answers are set up.
Questions - All of my questions for each catagory are in 1 text file like this
Question 1
Question 2
Question 3
Answers - I have it set up like multiple choice so my answers are all in 1 text file like my questions but each option is separated by / like this.
right answer/wrong answer/wrong answer
wrong answer/ right asnwer/ wrong answer
I appologize if what I am asking is confusing, I know that the way I have things organized and worded can be a bit confusing, I was just trying to include everything so that you would know exactly what I am trying to do with the code.