I've got an essential skills program which is very simple. The question is within the code. I want the question to be loaded from a text file.
I have already added some questions to the text file.
I have a list index where a random question will be picked from the text file and it will load as a label.
The issue is when I try to load the question I get a: System.ArgumentOutOfRangeException: ''minValue' cannot be greater than maxValue. Parameter name: minValue' error
Here is my code:
private void LoadQuestions()
{
if(Globals.intQuestionNumber == 11)
{
MessageBox.Show("Quiz complete - Redirecting", "Quiz Complete");
var fileStream = new FileStream(@"H:\(4)Programming\Assignments\EssentialSkills - Optimised\EssentialSkills\Numeracy\QuestionsLvl0.txt", FileMode.Open, FileAccess.Read);
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
string line;
while ((line = streamReader.ReadLine()) != null)
{
stringAllInfo.Add(line);
MessageBox.Show(line);
}
}
char[] delimiterChars = { ',' };
foreach (string l in stringAllInfo)
{
string[] words = l.Split(delimiterChars);
strQuestion.Add(words[0]);
strAnswer.Add(words[1]);
Console.WriteLine(words[0]);
Console.WriteLine(words[1]);
}
Menus.Summary sum = new Menus.Summary();
sum.Show();
this.Hide();
}
else
{
lblCountdownval.Visible = false;
lblCountdown.Visible = false;
Globals.intQuestionNumber += 0;
lblQuestionsNumber.Text = "Question Number: " + Globals.intQuestionNumber.ToString();
Random random = new Random();
Globals.listIndex = random.Next(0, strAnswer.Count - 1);
lblQuestion.Text = strQuestion.ElementAt(Globals.listIndex);
Globals.listQuestonsAsked.Add(strQuestion.ElementAt(Globals.listIndex));
btnCorrect.Text = strAnswer.ElementAt(Globals.listIndex).ToString();
btnAnswer1.Text = random.Next(200).ToString();
btnAnswer3.Text = random.Next(200).ToString();
int locationIndex = random.Next(0, 3);
btnCorrect.Location = points.ElementAt(locationIndex);
locationIndex = random.Next(0, 3);
btnAnswer1.Location = points.ElementAt(locationIndex);
while ((btnAnswer1.Location == btnCorrect.Location))
{
locationIndex = random.Next(0, 3);
btnAnswer1.Location = points.ElementAt(locationIndex);
}
locationIndex = random.Next(0, 3);
btnAnswer3.Location = points.ElementAt(locationIndex);
while ((btnAnswer3.Location == btnCorrect.Location) || (btnAnswer3.Location == btnAnswer1.Location))
{
locationIndex = random.Next(0, 3);
btnAnswer3.Location = points.ElementAt(locationIndex);
}
btnAnswer1.Show();
btnCorrect.BackColor = Color.White;
btnAnswer3.Show();
}
}
and here are my Lists:
public List<string> strQuestion = new List<string>();
public List<string> strAnswer = new List<string>();
public List<string> stringAllInfo = new List<string>();
I want the question from the text file to a label but I get that error.
Any advice?
Thanks.