wragen22
October 25th, 2008, 01:16 AM
Hello Folks,
I want to read information in a text file and then display it in a message box. I have both an employees class with a constructor and my form with the streamreader and arrays. I'm stuck at pulling the information out of the arrays. Any ideas? Here is my code
"amespace Employee_Homework
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] strTemp;
StreamReader sr;
sr = File.OpenText("file.txt");
Employees newEmployee;
while (sr.Peek() != -1)
{
strTemp = sr.ReadLine().Split(',');
newEmployee = new Employees(Convert.ToString(strTemp[0]), Convert.ToString(strTemp[1]), DateTime.Parse(strTemp[2]), Decimal.Parse(strTemp[3]));
MessageBox.Show(newEmployee.ToString());
}
}
}
}"
and my class:
class Employees
{
string e_name = "";
string e_position = "";
DateTime hire_date = Convert.ToDateTime("dd/mm/yyyy");
decimal e_salary = 0;
public string EmpName
{
get { return e_name;}
set { e_name = value; }
}
public string EnmpPosition
{
get { return e_position; }
set { e_position = value; }
}
public DateTime DateHired
{
get { return DateTime.Parse(e_position); }
set { hire_date = value; }
}
public decimal EmpSalary
{
get { return e_salary; }
set { e_salary = value; }
}
public Employees(string newName, string newPosition, DateTime newDate, decimal newSalary)
{
e_name = newName;
e_position = newPosition;
hire_date = newDate;
e_salary = newSalary;
}
}
}
I want to read information in a text file and then display it in a message box. I have both an employees class with a constructor and my form with the streamreader and arrays. I'm stuck at pulling the information out of the arrays. Any ideas? Here is my code
"amespace Employee_Homework
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] strTemp;
StreamReader sr;
sr = File.OpenText("file.txt");
Employees newEmployee;
while (sr.Peek() != -1)
{
strTemp = sr.ReadLine().Split(',');
newEmployee = new Employees(Convert.ToString(strTemp[0]), Convert.ToString(strTemp[1]), DateTime.Parse(strTemp[2]), Decimal.Parse(strTemp[3]));
MessageBox.Show(newEmployee.ToString());
}
}
}
}"
and my class:
class Employees
{
string e_name = "";
string e_position = "";
DateTime hire_date = Convert.ToDateTime("dd/mm/yyyy");
decimal e_salary = 0;
public string EmpName
{
get { return e_name;}
set { e_name = value; }
}
public string EnmpPosition
{
get { return e_position; }
set { e_position = value; }
}
public DateTime DateHired
{
get { return DateTime.Parse(e_position); }
set { hire_date = value; }
}
public decimal EmpSalary
{
get { return e_salary; }
set { e_salary = value; }
}
public Employees(string newName, string newPosition, DateTime newDate, decimal newSalary)
{
e_name = newName;
e_position = newPosition;
hire_date = newDate;
e_salary = newSalary;
}
}
}