I need to move to the next employee from a struct array.
I have this project pretty much complete except for changing the employee data from the array. I already have been graded for this project I would just like to know how to cycle through the array of employees. The name fields and the pay rate changes with the next button.
FroglegPosted Mar 3, 2011, 2:58 PM
while (sr.Peek() != -1)
{
//Collects the data abd fills the array of structures.
struc_EmployeeRecord EmpRecord = new struc_EmployeeRecord();
EmpRecord.firstname = sr.ReadLine();
EmpRecord.lastname = sr.ReadLine();
EmpRecord.payrate = sr.ReadLine();
//txtFirstName.Text = EmpRecord.firstname;
//txtLastName.Text = EmpRecord.lastname;
//txtPayRate.Text = EmpRecord.payrate;
EmployeeRecordArray[arrayindex] = EmpRecord;
arrayindex++;
}
txtFirstName.Text = EmployeeRecordArray[0].firstname;//start at first name in array
txtLastName.Text = EmployeeRecordArray[0].lastname;
txtPayRate.Text = EmployeeRecordArray[0].payrate;
}
catch
{
MessageBox.Show("File does not exist.");
}
In Vulpes code you will need add if statement so to ensure not incrementing currentIndex beyond size of the array. If it reaches array max, reset to 0
When you instantiate - EmployeeRecordArray = new struc_EmployeeRecord[26];
To instantiate properly use
int i = File.ReadAllLines(@"Employee.txt").Length;
int intIndex = i / 3; // count number of names
EmployeeRecordArray = new struc_EmployeeRecord[intIndex];
VulpesPosted Mar 3, 2011, 9:46 AM
Joel MackPosted Mar 3, 2011, 9:05 AM
FroglegPosted Mar 2, 2011, 8:02 PM
String path = @"Employee.txt"; - will look in same folder as your exe
you need to move through EmployeeRecordArray eg
private void btnNext_Click(object sender, EventArgs e)
{
txtFirstName.Text = EmployeeRecordArray[1].firstname;// increment 1 as needed
// fill other tectboxes as needed
}
See if you can work it out from here