G
Geoff Cox
Hello,
The code below works but could be improved I am told. I should use
private rather than static declarations.
The "correct" lines have // in front of them. But when I use those
lines I get an error message "Object
reference not set to an instance of an object" re following line
results[qnumber] = trackBar1.Value.ToString();
Any ideas please?
This is created using C# Visual Express Beta 2 - I could post the
other part of the code if helpful....
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
{
static string[] LHSquestions = {"question 1","question 2"};
static string[] RHSquestions = {"question 1", "question 2" };
//private string[] LHSquestions;
//private string[] RHSquestions;
private int qnumber = 0;
private string[] results = new string[LHSquestions.Length];
//private string[] results;
private int count = 0;
public Form1()
{
InitializeComponent();
//string[] LHSquestions = {"question 1","question 2"};
//string[] RHSquestions = {"question 1","question 2"};
//string[] results = new string[LHSquestions.Length];
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)
{
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("q" + (count+1) + " = " + results[count]);
}
tw.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
The code below works but could be improved I am told. I should use
private rather than static declarations.
The "correct" lines have // in front of them. But when I use those
lines I get an error message "Object
reference not set to an instance of an object" re following line
results[qnumber] = trackBar1.Value.ToString();
Any ideas please?
This is created using C# Visual Express Beta 2 - I could post the
other part of the code if helpful....
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
{
static string[] LHSquestions = {"question 1","question 2"};
static string[] RHSquestions = {"question 1", "question 2" };
//private string[] LHSquestions;
//private string[] RHSquestions;
private int qnumber = 0;
private string[] results = new string[LHSquestions.Length];
//private string[] results;
private int count = 0;
public Form1()
{
InitializeComponent();
//string[] LHSquestions = {"question 1","question 2"};
//string[] RHSquestions = {"question 1","question 2"};
//string[] results = new string[LHSquestions.Length];
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)
{
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("q" + (count+1) + " = " + results[count]);
}
tw.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}