Rather, I would wait until you have all the values (store them in
memory), and then write them to the file once when the operation is
complete.
Nicholas,
I'm trying the code below but when I click the button after the 2nd
question has appeared 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 ...
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)
{
}
}
}