G
Geoff Cox
Hello,
Ha
I get an "index out of bounds of the array" error message re the line
*** this.results[qnumber] = trackBar1.Value.ToString();
and cannot see why ...
The aim of the code is to display a series of images, each with a
slider. The user positions the pointer and then clicks on the button
to move to the next question and the slider value is put into an
array. After the last question clicking the button displays an "end"
message, the button is made invisible and all the slider values are
saved to a file.....
I'm new to C# and not sure how to see values for debugging. Have tried
Consile.WriteLine(value); but no value appears anywhere?!
Suggestions please!
Cheers
Geoff
------------------code-----------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace slider3
{
public partial class Form1 : Form
{
private string[] LHSquestions = {"question 1","question 2"};
private string[] RHSquestions = {"question 1", "question 2" };
private int qnumber = 0;
private string[] results = { "fred" };
private int count = 0;
public Form1()
{
InitializeComponent();
this.label1.Text = LHSquestions[qnumber];
this.label2.Text = RHSquestions[qnumber];
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
}
private void button1_MouseClick(object sender, MouseEventArgs
e)
{
*** this.results[qnumber] = trackBar1.Value.ToString();
++qnumber;
if (qnumber == LHSquestions.Length)
{
endMessage();
}
else
{
this.label1.Text = LHSquestions[qnumber];
this.label2.Text = RHSquestions[qnumber];
}
}
private void endMessage()
{
this.label1.Text = "Finished!";
this.label2.Text = "Thank you";
this.button1.Visible = false;
TextWriter tw = new StreamWriter("d:\\a-temp1\\data.txt");
for (count = 0; count < LHSquestions.Length; count++)
{
tw.WriteLine(results[qnumber]);
}
tw.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Ha
I get an "index out of bounds of the array" error message re the line
*** this.results[qnumber] = trackBar1.Value.ToString();
and cannot see why ...
The aim of the code is to display a series of images, each with a
slider. The user positions the pointer and then clicks on the button
to move to the next question and the slider value is put into an
array. After the last question clicking the button displays an "end"
message, the button is made invisible and all the slider values are
saved to a file.....
I'm new to C# and not sure how to see values for debugging. Have tried
Consile.WriteLine(value); but no value appears anywhere?!
Suggestions please!
Cheers
Geoff
------------------code-----------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace slider3
{
public partial class Form1 : Form
{
private string[] LHSquestions = {"question 1","question 2"};
private string[] RHSquestions = {"question 1", "question 2" };
private int qnumber = 0;
private string[] results = { "fred" };
private int count = 0;
public Form1()
{
InitializeComponent();
this.label1.Text = LHSquestions[qnumber];
this.label2.Text = RHSquestions[qnumber];
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
}
private void button1_MouseClick(object sender, MouseEventArgs
e)
{
*** this.results[qnumber] = trackBar1.Value.ToString();
++qnumber;
if (qnumber == LHSquestions.Length)
{
endMessage();
}
else
{
this.label1.Text = LHSquestions[qnumber];
this.label2.Text = RHSquestions[qnumber];
}
}
private void endMessage()
{
this.label1.Text = "Finished!";
this.label2.Text = "Thank you";
this.button1.Visible = false;
TextWriter tw = new StreamWriter("d:\\a-temp1\\data.txt");
for (count = 0; count < LHSquestions.Length; count++)
{
tw.WriteLine(results[qnumber]);
}
tw.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}