Still Learning 'System.StackOverflowException' was thrown.'












-4















I have tried if, else if, else statements, I have tried nested if statements. I have tried using variables in place of if statements. Everything functions except the Team Leader portion, there is an issue with the "TrainHours," and the repetition that it is being used, after that is corrected there is an issue with "Hours," the latest corrections was with the "GetPay()."



I have tried every different way that I can find online, and in my textbooks, but no matter what I do I get



"'System.StackOverflowException' was thrown.'"



-OR-



"'Unknown error in unknown module Exception'"



-personal gratitude removed for moderators- jeets82(edited)



Main Form:



public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void proWorker_Click(object sender, EventArgs e)
{
string pName, pShift;
decimal pOTime, pPay;

pName = pNameTxt.Text;


if (pName != "" &&
int.TryParse(pNumTxt.Text, out int pNum) &&
decimal.TryParse(pHRateTxt.Text, out decimal pHRate) &&
decimal.TryParse(pHoursTxt.Text, out decimal pHours))
{
if (dayBtn.Checked)
{
ProductionWorker pWorker1 = new ProductionWorker();
pPay = pWorker1.getPay();
pOTime = pWorker1.Overtime();

pShift = "Day";
ProductionWorker pWorker = new ProductionWorker(pName, pNum, pShift, pHRate, pHours, pOTime, pPay);

MessageBox.Show(pWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("proWorkerDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(pWorker.getProWorkerFile());

empFile.Close();
}

if (nightBtn.Checked)
{
ProductionWorker pWorker2 = new ProductionWorker();
pPay = pWorker2.getPay();
pOTime = pWorker2.Overtime();
pShift = "Night";

ProductionWorker pWorker2N = new ProductionWorker(pName, pNum, pShift, pHRate, pHours, pOTime, pPay);
MessageBox.Show(pWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("proWorkerNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(pWorker2N.getProWorkerFile());

empFile.Close();
}
}

else
{
MessageBox.Show("Enter valid Production worker information");
}

pNameTxt.Text = "";
pNumTxt.Text = "";
pHRateTxt.Text = "";
pHoursTxt.Text = "";
}

private void addEmp_Click(object sender, EventArgs e)
{
string eName;
int eNum;
eName = eNameTxt.Text;

if (Name != "" && int.TryParse(eNumTxt.Text, out eNum))
{

Employee employee = new Employee(eName, eNum);

MessageBox.Show(employee.getData());

StreamWriter empFile;
empFile = File.AppendText("EmployeeFile.txt");

Employee aEmp = new Employee();

empFile.WriteLine(employee.getEmployeeFile());

empFile.Close();
}

else
{
MessageBox.Show("Enter valid employee information.");
}


}

private void byeBtn_Click(object sender, EventArgs e)
{
this.Close();
}

private void sAddBtn_Click(object sender, EventArgs e)
{
string sName, sShift;
decimal sPay;

sName = sNameTxt.Text;

if (sName != "" &&
int.TryParse(sNumTxt.Text, out int sNum) &&
decimal.TryParse(sSalTxt.Text, out decimal sSal) &&
decimal.TryParse(sBonusTxt.Text, out decimal sBonus))
{

if (sDayBtn.Checked)
{
ShiftSupervisor sWorker1 = new ShiftSupervisor();
sPay = sWorker1.getSPay();

sShift = "Day";
ShiftSupervisor sWorker = new ShiftSupervisor(sName, sNum, sShift, sSal, sBonus, sPay);

MessageBox.Show(sWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("sWorkerDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(sWorker.getSWorkerFile());

empFile.Close();
}

if (sNightBtn.Checked)
{
ShiftSupervisor sWorker2 = new ShiftSupervisor();
sPay = sWorker2.getSPay();

sShift = "Night";
ShiftSupervisor sWorker2N = new ShiftSupervisor(sName, sNum, sShift, sSal, sBonus, sPay);
MessageBox.Show(sWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("sWorkerNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(sWorker2N.getSWorkerFile());

empFile.Close();
}

}

else
{
MessageBox.Show("Enter valid Shift Supervisor information.");
}

sNameTxt.Text = "";
sNumTxt.Text = "";
sSalTxt.Text = "";
sBonusTxt.Text = "";
}

private void addTLBtn_Click(object sender, EventArgs e)
{
string tName, tShift;
decimal tOTime, tPay;

tName = tNameTxt.Text;


if (tName != "" &&
int.TryParse(tNumTxt.Text, out int tNum) &&
decimal.TryParse(tHRateTxt.Text, out decimal tHRate) &&
decimal.TryParse(tHoursTxt.Text, out decimal tHours) &&
decimal.TryParse(tTrainTxt.Text, out decimal tTrain))
{
if (tDayBtn.Checked)
{
TeamLeader tWorker1 = new TeamLeader();
tPay = tWorker1.getTPay();
tOTime = tWorker1.Overtime();
decimal rHours = tWorker1.ReqHours;
decimal tTHours = tWorker1.TrainHours;

tShift = "Day";
TeamLeader tWorker = new TeamLeader(tName, tNum, tShift, tHRate, tHours, tOTime, rHours, tTHours, tPay);

MessageBox.Show(tWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("TeamLeaderDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(tWorker.getTeamLeaderFile());

empFile.Close();
}

if (tNightBtn.Checked)
{
TeamLeader tWorker2 = new TeamLeader();
tPay = tWorker2.getTPay();
tOTime = tWorker2.Overtime();
decimal rHours = tWorker2.ReqHours;
decimal tTHours = tWorker2.TrainHours;

tShift = "Day";
TeamLeader tWorker2N = new TeamLeader(tName, tNum, tShift, tHRate, tHours, tOTime, rHours, tTHours, tPay);
MessageBox.Show(tWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("TeamLeaderNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(tWorker2N.getTeamLeaderFile());

empFile.Close();
}
}

else
{
MessageBox.Show("Enter valid Production worker information");
}

tNameTxt.Text = "";
tNumTxt.Text = "";
tHRateTxt.Text = "";
tHoursTxt.Text = "";
tTrainTxt.Text = "";
}
}


Base Class:



class Employee
{
private string _name;
private int _number;
private string _empAddList;

public Employee(string name, int num)
{
_name = name;
_number = num;
_empAddList = name + " " + num.ToString();
}

public Employee()
{
_name = "";
_number = 0;
}

public string Name
{
get { return _name; }
set { _name = value; }
}

public int Number
{
get { return _number; }
set { _number = value; }
}

public string EmpAddList
{
get { return _empAddList; }
set { _empAddList = value; }
}

//define method to return the values
public virtual string getData()
{
string line = "";
line += " Name: tt" + this.Name + "n";
line += " Number: t" + this.Number;
return line;
}

public string getEmployeeFile()
{
string line = "";
line += this.Name + "," + this.Number;
return line;
}

}

abstract class Employee1 : Employee
{
public abstract decimal Overtime();
public abstract decimal getPay();
}


PROBLEM CLASS I have fixed almost every portion and every time I fix something it gives me a different error or StackOverflowException.



class TeamLeader : Employee
{
private string _shiftNum;
private decimal _hourlyRate;
private decimal _reqHours;
private decimal _trainHours;
private decimal _hours;
private decimal _overtime;
private decimal _oT;


public string ShiftNum
{
get { return _shiftNum; }
set
{
if (_shiftNum == "Day Shift")
{
_shiftNum = "Day";
}

else
{
_shiftNum = "Night";
}
}
}

public decimal HourlyRate
{
get { return _hourlyRate; }
set { _hourlyRate = value; }
}

public decimal Hours
{
get { return _hours; }
set { _hours = value; }
}

public decimal ReqHours
{
get { return _reqHours; }
set { _reqHours = value; }
}

public decimal TrainHours
{
get { return _trainHours; }
set { _trainHours = value; }
}

public decimal Overtime()
{
decimal oTime = 0;

if (Hours > 40)
{
_oT = Hours - 40;
oTime = (HourlyRate * 1.5m) * _oT;
}

else
{
oTime = 0;
}

return oTime;
}

public decimal getTBonus()
{
decimal tBonus = 0;
if (TrainHours <= 0 && Hours <= 0)
{ tBonus = 0; }

if (TrainHours >= (Hours * .15m))
{ tBonus = getTPay() * .15m; }

if (TrainHours >= (Hours * .1m))
{ tBonus = getTPay() * .125m; }

if (TrainHours >= (Hours * .08m))
{ tBonus = getTPay() * .05m; }

else
{ tBonus = getTPay() * .025m; }

return tBonus;
}

public decimal getTTrainHours()
{
decimal tHours = 0;
if (TrainHours <= 0 && Hours <= 0)
{ tHours = 0; }

if (TrainHours >= (Hours * .15m))
{ tHours = Hours * .15m; }

else if (TrainHours <= (Hours * .1m))
{ tHours = Hours * .125m; }

else if (TrainHours <= (Hours * .08m))
{ tHours = Hours * .05m; }

else
{ tHours = Hours * .025m; }

return tHours;
}

public decimal getTPay()
{
decimal paid = 0;

if (Hours <= 0)
{ paid = 0; }

if (Hours > 40)
{ paid = (HourlyRate * 40) + Overtime() + getTBonus(); }

else
{ paid = (Hours * HourlyRate) + getTBonus(); }

return paid;
}

public TeamLeader(string name, int num, string shift, decimal hr, decimal hours, decimal oTime, decimal rHours, decimal tTHours, decimal pay) : base(name, num)
{
_shiftNum = shift;
_hourlyRate = hr;
_hours = hours;
_overtime = oTime;
_trainHours = rHours;
_reqHours = tTHours;

}

public TeamLeader()
{
_shiftNum = "";
_hourlyRate = 0;
_hours = 0;
_overtime = 0;
_trainHours = 0;
_reqHours = 0;
}

public override string getData()
{
string line = "";
line += " Name: t" + this.Name + "n";
line += " Number: t" + this.Number + "n";
line += " Shift Number: t" + this.ShiftNum + "n";
line += " Hourly Rate: t" + this.HourlyRate.ToString("C") + "n";
line += " Hours Worked: t" + this.Hours + "n";
line += " Training Hours: t" + this.TrainHours.ToString() + "n";
line += " Overtime Hours: t" + (this.Hours - 40) + "n";
line += " Overtime Pay: t" + this.Overtime().ToString("C") + "n";
line += " Bonus Multiplier: t" + this.getTTrainHours().ToString("P") + "n";
line += " Bonus: t" + this.getTBonus().ToString("C") + "n";
line += " Weekly Pay: t" + this.getTPay().ToString("C");

return line;
}

public string getTeamLeaderFile()
{
string line = "";
line += this.Name + "," + this.Number + "," + this.ShiftNum + "," + this.HourlyRate.ToString() + "," + this.Hours + "," + this.TrainHours.ToString() + "," + (this.Hours - 40) + "," +
this.Overtime().ToString() + "," + this.getTTrainHours().ToString("P") + "," + this.getTBonus().ToString("C") + "," + this.getTPay().ToString();
return line;
}
}


}










share|improve this question




















  • 3





    Welcome to StackOverflow. There's a joke about a speak-your-weight machine, where a large person stands on it, and it says "one person at a time, please!". This question is a bit like that. Your question needs to focus on one issue. You need to provide a Minimal, Complete, and Verifiable example (for example, edit your question to remove all the commented code). Pick one exception, and show us the code when that happens; and tell us what line it happens on. I sympathise with the background info, but it's not relevant to the question: try to focus on the issue. The "how to ask" uses the phrase "talking to a busy colleague".

    – Richardissimo
    Nov 23 '18 at 6:16











  • I didn't down vote. I'm trying to help. You mentioned 2 exceptions, not just one. Your experience here will be bad if you don't learn How to ask. For example, let me offer this unrelated tip: StreamWriter is IDisposable so should be in a using block. Once you've done that, you don't need to Close it because it will be closed by the implicit Dispose as it exits the block.

    – Richardissimo
    Nov 23 '18 at 6:58











  • I'd like to clarify and apologize. I had directed that portion at @Uwe Keim who did downvote my question without explanation and removed a pre-emptive appreciation I had shown. Do you have some direction on how to better phrase my question? I will gladly try to be more direct.

    – jeets82
    Nov 23 '18 at 7:07











  • No problem: as you said yourself, we've all been there, and glad you found your answer. Don't take the down votes to heart - StackOverflow is a powerful tool; but one has to learn how to use it. There are lots of tips on the 'How to ask' page, and the MCVE page is regularly quoted, and applies here: It is all too easy to just throw a load of code at StackOverflow and say "help!", but that does not make a good question, and I fear this question strayed too much in that direction, which may have drawn the down votes. Look on meta.stackoverflow.com for info on how people use this site.Best wishes

    – Richardissimo
    Nov 23 '18 at 21:19











  • @Richardissimo I would like to thank you. It took some time. Another whole day in fact, but I learned to use the: FileStream, and: Using to achieve the IDisposable. Thank you.

    – jeets82
    Nov 25 '18 at 1:26
















-4















I have tried if, else if, else statements, I have tried nested if statements. I have tried using variables in place of if statements. Everything functions except the Team Leader portion, there is an issue with the "TrainHours," and the repetition that it is being used, after that is corrected there is an issue with "Hours," the latest corrections was with the "GetPay()."



I have tried every different way that I can find online, and in my textbooks, but no matter what I do I get



"'System.StackOverflowException' was thrown.'"



-OR-



"'Unknown error in unknown module Exception'"



-personal gratitude removed for moderators- jeets82(edited)



Main Form:



public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void proWorker_Click(object sender, EventArgs e)
{
string pName, pShift;
decimal pOTime, pPay;

pName = pNameTxt.Text;


if (pName != "" &&
int.TryParse(pNumTxt.Text, out int pNum) &&
decimal.TryParse(pHRateTxt.Text, out decimal pHRate) &&
decimal.TryParse(pHoursTxt.Text, out decimal pHours))
{
if (dayBtn.Checked)
{
ProductionWorker pWorker1 = new ProductionWorker();
pPay = pWorker1.getPay();
pOTime = pWorker1.Overtime();

pShift = "Day";
ProductionWorker pWorker = new ProductionWorker(pName, pNum, pShift, pHRate, pHours, pOTime, pPay);

MessageBox.Show(pWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("proWorkerDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(pWorker.getProWorkerFile());

empFile.Close();
}

if (nightBtn.Checked)
{
ProductionWorker pWorker2 = new ProductionWorker();
pPay = pWorker2.getPay();
pOTime = pWorker2.Overtime();
pShift = "Night";

ProductionWorker pWorker2N = new ProductionWorker(pName, pNum, pShift, pHRate, pHours, pOTime, pPay);
MessageBox.Show(pWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("proWorkerNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(pWorker2N.getProWorkerFile());

empFile.Close();
}
}

else
{
MessageBox.Show("Enter valid Production worker information");
}

pNameTxt.Text = "";
pNumTxt.Text = "";
pHRateTxt.Text = "";
pHoursTxt.Text = "";
}

private void addEmp_Click(object sender, EventArgs e)
{
string eName;
int eNum;
eName = eNameTxt.Text;

if (Name != "" && int.TryParse(eNumTxt.Text, out eNum))
{

Employee employee = new Employee(eName, eNum);

MessageBox.Show(employee.getData());

StreamWriter empFile;
empFile = File.AppendText("EmployeeFile.txt");

Employee aEmp = new Employee();

empFile.WriteLine(employee.getEmployeeFile());

empFile.Close();
}

else
{
MessageBox.Show("Enter valid employee information.");
}


}

private void byeBtn_Click(object sender, EventArgs e)
{
this.Close();
}

private void sAddBtn_Click(object sender, EventArgs e)
{
string sName, sShift;
decimal sPay;

sName = sNameTxt.Text;

if (sName != "" &&
int.TryParse(sNumTxt.Text, out int sNum) &&
decimal.TryParse(sSalTxt.Text, out decimal sSal) &&
decimal.TryParse(sBonusTxt.Text, out decimal sBonus))
{

if (sDayBtn.Checked)
{
ShiftSupervisor sWorker1 = new ShiftSupervisor();
sPay = sWorker1.getSPay();

sShift = "Day";
ShiftSupervisor sWorker = new ShiftSupervisor(sName, sNum, sShift, sSal, sBonus, sPay);

MessageBox.Show(sWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("sWorkerDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(sWorker.getSWorkerFile());

empFile.Close();
}

if (sNightBtn.Checked)
{
ShiftSupervisor sWorker2 = new ShiftSupervisor();
sPay = sWorker2.getSPay();

sShift = "Night";
ShiftSupervisor sWorker2N = new ShiftSupervisor(sName, sNum, sShift, sSal, sBonus, sPay);
MessageBox.Show(sWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("sWorkerNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(sWorker2N.getSWorkerFile());

empFile.Close();
}

}

else
{
MessageBox.Show("Enter valid Shift Supervisor information.");
}

sNameTxt.Text = "";
sNumTxt.Text = "";
sSalTxt.Text = "";
sBonusTxt.Text = "";
}

private void addTLBtn_Click(object sender, EventArgs e)
{
string tName, tShift;
decimal tOTime, tPay;

tName = tNameTxt.Text;


if (tName != "" &&
int.TryParse(tNumTxt.Text, out int tNum) &&
decimal.TryParse(tHRateTxt.Text, out decimal tHRate) &&
decimal.TryParse(tHoursTxt.Text, out decimal tHours) &&
decimal.TryParse(tTrainTxt.Text, out decimal tTrain))
{
if (tDayBtn.Checked)
{
TeamLeader tWorker1 = new TeamLeader();
tPay = tWorker1.getTPay();
tOTime = tWorker1.Overtime();
decimal rHours = tWorker1.ReqHours;
decimal tTHours = tWorker1.TrainHours;

tShift = "Day";
TeamLeader tWorker = new TeamLeader(tName, tNum, tShift, tHRate, tHours, tOTime, rHours, tTHours, tPay);

MessageBox.Show(tWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("TeamLeaderDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(tWorker.getTeamLeaderFile());

empFile.Close();
}

if (tNightBtn.Checked)
{
TeamLeader tWorker2 = new TeamLeader();
tPay = tWorker2.getTPay();
tOTime = tWorker2.Overtime();
decimal rHours = tWorker2.ReqHours;
decimal tTHours = tWorker2.TrainHours;

tShift = "Day";
TeamLeader tWorker2N = new TeamLeader(tName, tNum, tShift, tHRate, tHours, tOTime, rHours, tTHours, tPay);
MessageBox.Show(tWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("TeamLeaderNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(tWorker2N.getTeamLeaderFile());

empFile.Close();
}
}

else
{
MessageBox.Show("Enter valid Production worker information");
}

tNameTxt.Text = "";
tNumTxt.Text = "";
tHRateTxt.Text = "";
tHoursTxt.Text = "";
tTrainTxt.Text = "";
}
}


Base Class:



class Employee
{
private string _name;
private int _number;
private string _empAddList;

public Employee(string name, int num)
{
_name = name;
_number = num;
_empAddList = name + " " + num.ToString();
}

public Employee()
{
_name = "";
_number = 0;
}

public string Name
{
get { return _name; }
set { _name = value; }
}

public int Number
{
get { return _number; }
set { _number = value; }
}

public string EmpAddList
{
get { return _empAddList; }
set { _empAddList = value; }
}

//define method to return the values
public virtual string getData()
{
string line = "";
line += " Name: tt" + this.Name + "n";
line += " Number: t" + this.Number;
return line;
}

public string getEmployeeFile()
{
string line = "";
line += this.Name + "," + this.Number;
return line;
}

}

abstract class Employee1 : Employee
{
public abstract decimal Overtime();
public abstract decimal getPay();
}


PROBLEM CLASS I have fixed almost every portion and every time I fix something it gives me a different error or StackOverflowException.



class TeamLeader : Employee
{
private string _shiftNum;
private decimal _hourlyRate;
private decimal _reqHours;
private decimal _trainHours;
private decimal _hours;
private decimal _overtime;
private decimal _oT;


public string ShiftNum
{
get { return _shiftNum; }
set
{
if (_shiftNum == "Day Shift")
{
_shiftNum = "Day";
}

else
{
_shiftNum = "Night";
}
}
}

public decimal HourlyRate
{
get { return _hourlyRate; }
set { _hourlyRate = value; }
}

public decimal Hours
{
get { return _hours; }
set { _hours = value; }
}

public decimal ReqHours
{
get { return _reqHours; }
set { _reqHours = value; }
}

public decimal TrainHours
{
get { return _trainHours; }
set { _trainHours = value; }
}

public decimal Overtime()
{
decimal oTime = 0;

if (Hours > 40)
{
_oT = Hours - 40;
oTime = (HourlyRate * 1.5m) * _oT;
}

else
{
oTime = 0;
}

return oTime;
}

public decimal getTBonus()
{
decimal tBonus = 0;
if (TrainHours <= 0 && Hours <= 0)
{ tBonus = 0; }

if (TrainHours >= (Hours * .15m))
{ tBonus = getTPay() * .15m; }

if (TrainHours >= (Hours * .1m))
{ tBonus = getTPay() * .125m; }

if (TrainHours >= (Hours * .08m))
{ tBonus = getTPay() * .05m; }

else
{ tBonus = getTPay() * .025m; }

return tBonus;
}

public decimal getTTrainHours()
{
decimal tHours = 0;
if (TrainHours <= 0 && Hours <= 0)
{ tHours = 0; }

if (TrainHours >= (Hours * .15m))
{ tHours = Hours * .15m; }

else if (TrainHours <= (Hours * .1m))
{ tHours = Hours * .125m; }

else if (TrainHours <= (Hours * .08m))
{ tHours = Hours * .05m; }

else
{ tHours = Hours * .025m; }

return tHours;
}

public decimal getTPay()
{
decimal paid = 0;

if (Hours <= 0)
{ paid = 0; }

if (Hours > 40)
{ paid = (HourlyRate * 40) + Overtime() + getTBonus(); }

else
{ paid = (Hours * HourlyRate) + getTBonus(); }

return paid;
}

public TeamLeader(string name, int num, string shift, decimal hr, decimal hours, decimal oTime, decimal rHours, decimal tTHours, decimal pay) : base(name, num)
{
_shiftNum = shift;
_hourlyRate = hr;
_hours = hours;
_overtime = oTime;
_trainHours = rHours;
_reqHours = tTHours;

}

public TeamLeader()
{
_shiftNum = "";
_hourlyRate = 0;
_hours = 0;
_overtime = 0;
_trainHours = 0;
_reqHours = 0;
}

public override string getData()
{
string line = "";
line += " Name: t" + this.Name + "n";
line += " Number: t" + this.Number + "n";
line += " Shift Number: t" + this.ShiftNum + "n";
line += " Hourly Rate: t" + this.HourlyRate.ToString("C") + "n";
line += " Hours Worked: t" + this.Hours + "n";
line += " Training Hours: t" + this.TrainHours.ToString() + "n";
line += " Overtime Hours: t" + (this.Hours - 40) + "n";
line += " Overtime Pay: t" + this.Overtime().ToString("C") + "n";
line += " Bonus Multiplier: t" + this.getTTrainHours().ToString("P") + "n";
line += " Bonus: t" + this.getTBonus().ToString("C") + "n";
line += " Weekly Pay: t" + this.getTPay().ToString("C");

return line;
}

public string getTeamLeaderFile()
{
string line = "";
line += this.Name + "," + this.Number + "," + this.ShiftNum + "," + this.HourlyRate.ToString() + "," + this.Hours + "," + this.TrainHours.ToString() + "," + (this.Hours - 40) + "," +
this.Overtime().ToString() + "," + this.getTTrainHours().ToString("P") + "," + this.getTBonus().ToString("C") + "," + this.getTPay().ToString();
return line;
}
}


}










share|improve this question




















  • 3





    Welcome to StackOverflow. There's a joke about a speak-your-weight machine, where a large person stands on it, and it says "one person at a time, please!". This question is a bit like that. Your question needs to focus on one issue. You need to provide a Minimal, Complete, and Verifiable example (for example, edit your question to remove all the commented code). Pick one exception, and show us the code when that happens; and tell us what line it happens on. I sympathise with the background info, but it's not relevant to the question: try to focus on the issue. The "how to ask" uses the phrase "talking to a busy colleague".

    – Richardissimo
    Nov 23 '18 at 6:16











  • I didn't down vote. I'm trying to help. You mentioned 2 exceptions, not just one. Your experience here will be bad if you don't learn How to ask. For example, let me offer this unrelated tip: StreamWriter is IDisposable so should be in a using block. Once you've done that, you don't need to Close it because it will be closed by the implicit Dispose as it exits the block.

    – Richardissimo
    Nov 23 '18 at 6:58











  • I'd like to clarify and apologize. I had directed that portion at @Uwe Keim who did downvote my question without explanation and removed a pre-emptive appreciation I had shown. Do you have some direction on how to better phrase my question? I will gladly try to be more direct.

    – jeets82
    Nov 23 '18 at 7:07











  • No problem: as you said yourself, we've all been there, and glad you found your answer. Don't take the down votes to heart - StackOverflow is a powerful tool; but one has to learn how to use it. There are lots of tips on the 'How to ask' page, and the MCVE page is regularly quoted, and applies here: It is all too easy to just throw a load of code at StackOverflow and say "help!", but that does not make a good question, and I fear this question strayed too much in that direction, which may have drawn the down votes. Look on meta.stackoverflow.com for info on how people use this site.Best wishes

    – Richardissimo
    Nov 23 '18 at 21:19











  • @Richardissimo I would like to thank you. It took some time. Another whole day in fact, but I learned to use the: FileStream, and: Using to achieve the IDisposable. Thank you.

    – jeets82
    Nov 25 '18 at 1:26














-4












-4








-4








I have tried if, else if, else statements, I have tried nested if statements. I have tried using variables in place of if statements. Everything functions except the Team Leader portion, there is an issue with the "TrainHours," and the repetition that it is being used, after that is corrected there is an issue with "Hours," the latest corrections was with the "GetPay()."



I have tried every different way that I can find online, and in my textbooks, but no matter what I do I get



"'System.StackOverflowException' was thrown.'"



-OR-



"'Unknown error in unknown module Exception'"



-personal gratitude removed for moderators- jeets82(edited)



Main Form:



public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void proWorker_Click(object sender, EventArgs e)
{
string pName, pShift;
decimal pOTime, pPay;

pName = pNameTxt.Text;


if (pName != "" &&
int.TryParse(pNumTxt.Text, out int pNum) &&
decimal.TryParse(pHRateTxt.Text, out decimal pHRate) &&
decimal.TryParse(pHoursTxt.Text, out decimal pHours))
{
if (dayBtn.Checked)
{
ProductionWorker pWorker1 = new ProductionWorker();
pPay = pWorker1.getPay();
pOTime = pWorker1.Overtime();

pShift = "Day";
ProductionWorker pWorker = new ProductionWorker(pName, pNum, pShift, pHRate, pHours, pOTime, pPay);

MessageBox.Show(pWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("proWorkerDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(pWorker.getProWorkerFile());

empFile.Close();
}

if (nightBtn.Checked)
{
ProductionWorker pWorker2 = new ProductionWorker();
pPay = pWorker2.getPay();
pOTime = pWorker2.Overtime();
pShift = "Night";

ProductionWorker pWorker2N = new ProductionWorker(pName, pNum, pShift, pHRate, pHours, pOTime, pPay);
MessageBox.Show(pWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("proWorkerNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(pWorker2N.getProWorkerFile());

empFile.Close();
}
}

else
{
MessageBox.Show("Enter valid Production worker information");
}

pNameTxt.Text = "";
pNumTxt.Text = "";
pHRateTxt.Text = "";
pHoursTxt.Text = "";
}

private void addEmp_Click(object sender, EventArgs e)
{
string eName;
int eNum;
eName = eNameTxt.Text;

if (Name != "" && int.TryParse(eNumTxt.Text, out eNum))
{

Employee employee = new Employee(eName, eNum);

MessageBox.Show(employee.getData());

StreamWriter empFile;
empFile = File.AppendText("EmployeeFile.txt");

Employee aEmp = new Employee();

empFile.WriteLine(employee.getEmployeeFile());

empFile.Close();
}

else
{
MessageBox.Show("Enter valid employee information.");
}


}

private void byeBtn_Click(object sender, EventArgs e)
{
this.Close();
}

private void sAddBtn_Click(object sender, EventArgs e)
{
string sName, sShift;
decimal sPay;

sName = sNameTxt.Text;

if (sName != "" &&
int.TryParse(sNumTxt.Text, out int sNum) &&
decimal.TryParse(sSalTxt.Text, out decimal sSal) &&
decimal.TryParse(sBonusTxt.Text, out decimal sBonus))
{

if (sDayBtn.Checked)
{
ShiftSupervisor sWorker1 = new ShiftSupervisor();
sPay = sWorker1.getSPay();

sShift = "Day";
ShiftSupervisor sWorker = new ShiftSupervisor(sName, sNum, sShift, sSal, sBonus, sPay);

MessageBox.Show(sWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("sWorkerDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(sWorker.getSWorkerFile());

empFile.Close();
}

if (sNightBtn.Checked)
{
ShiftSupervisor sWorker2 = new ShiftSupervisor();
sPay = sWorker2.getSPay();

sShift = "Night";
ShiftSupervisor sWorker2N = new ShiftSupervisor(sName, sNum, sShift, sSal, sBonus, sPay);
MessageBox.Show(sWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("sWorkerNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(sWorker2N.getSWorkerFile());

empFile.Close();
}

}

else
{
MessageBox.Show("Enter valid Shift Supervisor information.");
}

sNameTxt.Text = "";
sNumTxt.Text = "";
sSalTxt.Text = "";
sBonusTxt.Text = "";
}

private void addTLBtn_Click(object sender, EventArgs e)
{
string tName, tShift;
decimal tOTime, tPay;

tName = tNameTxt.Text;


if (tName != "" &&
int.TryParse(tNumTxt.Text, out int tNum) &&
decimal.TryParse(tHRateTxt.Text, out decimal tHRate) &&
decimal.TryParse(tHoursTxt.Text, out decimal tHours) &&
decimal.TryParse(tTrainTxt.Text, out decimal tTrain))
{
if (tDayBtn.Checked)
{
TeamLeader tWorker1 = new TeamLeader();
tPay = tWorker1.getTPay();
tOTime = tWorker1.Overtime();
decimal rHours = tWorker1.ReqHours;
decimal tTHours = tWorker1.TrainHours;

tShift = "Day";
TeamLeader tWorker = new TeamLeader(tName, tNum, tShift, tHRate, tHours, tOTime, rHours, tTHours, tPay);

MessageBox.Show(tWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("TeamLeaderDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(tWorker.getTeamLeaderFile());

empFile.Close();
}

if (tNightBtn.Checked)
{
TeamLeader tWorker2 = new TeamLeader();
tPay = tWorker2.getTPay();
tOTime = tWorker2.Overtime();
decimal rHours = tWorker2.ReqHours;
decimal tTHours = tWorker2.TrainHours;

tShift = "Day";
TeamLeader tWorker2N = new TeamLeader(tName, tNum, tShift, tHRate, tHours, tOTime, rHours, tTHours, tPay);
MessageBox.Show(tWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("TeamLeaderNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(tWorker2N.getTeamLeaderFile());

empFile.Close();
}
}

else
{
MessageBox.Show("Enter valid Production worker information");
}

tNameTxt.Text = "";
tNumTxt.Text = "";
tHRateTxt.Text = "";
tHoursTxt.Text = "";
tTrainTxt.Text = "";
}
}


Base Class:



class Employee
{
private string _name;
private int _number;
private string _empAddList;

public Employee(string name, int num)
{
_name = name;
_number = num;
_empAddList = name + " " + num.ToString();
}

public Employee()
{
_name = "";
_number = 0;
}

public string Name
{
get { return _name; }
set { _name = value; }
}

public int Number
{
get { return _number; }
set { _number = value; }
}

public string EmpAddList
{
get { return _empAddList; }
set { _empAddList = value; }
}

//define method to return the values
public virtual string getData()
{
string line = "";
line += " Name: tt" + this.Name + "n";
line += " Number: t" + this.Number;
return line;
}

public string getEmployeeFile()
{
string line = "";
line += this.Name + "," + this.Number;
return line;
}

}

abstract class Employee1 : Employee
{
public abstract decimal Overtime();
public abstract decimal getPay();
}


PROBLEM CLASS I have fixed almost every portion and every time I fix something it gives me a different error or StackOverflowException.



class TeamLeader : Employee
{
private string _shiftNum;
private decimal _hourlyRate;
private decimal _reqHours;
private decimal _trainHours;
private decimal _hours;
private decimal _overtime;
private decimal _oT;


public string ShiftNum
{
get { return _shiftNum; }
set
{
if (_shiftNum == "Day Shift")
{
_shiftNum = "Day";
}

else
{
_shiftNum = "Night";
}
}
}

public decimal HourlyRate
{
get { return _hourlyRate; }
set { _hourlyRate = value; }
}

public decimal Hours
{
get { return _hours; }
set { _hours = value; }
}

public decimal ReqHours
{
get { return _reqHours; }
set { _reqHours = value; }
}

public decimal TrainHours
{
get { return _trainHours; }
set { _trainHours = value; }
}

public decimal Overtime()
{
decimal oTime = 0;

if (Hours > 40)
{
_oT = Hours - 40;
oTime = (HourlyRate * 1.5m) * _oT;
}

else
{
oTime = 0;
}

return oTime;
}

public decimal getTBonus()
{
decimal tBonus = 0;
if (TrainHours <= 0 && Hours <= 0)
{ tBonus = 0; }

if (TrainHours >= (Hours * .15m))
{ tBonus = getTPay() * .15m; }

if (TrainHours >= (Hours * .1m))
{ tBonus = getTPay() * .125m; }

if (TrainHours >= (Hours * .08m))
{ tBonus = getTPay() * .05m; }

else
{ tBonus = getTPay() * .025m; }

return tBonus;
}

public decimal getTTrainHours()
{
decimal tHours = 0;
if (TrainHours <= 0 && Hours <= 0)
{ tHours = 0; }

if (TrainHours >= (Hours * .15m))
{ tHours = Hours * .15m; }

else if (TrainHours <= (Hours * .1m))
{ tHours = Hours * .125m; }

else if (TrainHours <= (Hours * .08m))
{ tHours = Hours * .05m; }

else
{ tHours = Hours * .025m; }

return tHours;
}

public decimal getTPay()
{
decimal paid = 0;

if (Hours <= 0)
{ paid = 0; }

if (Hours > 40)
{ paid = (HourlyRate * 40) + Overtime() + getTBonus(); }

else
{ paid = (Hours * HourlyRate) + getTBonus(); }

return paid;
}

public TeamLeader(string name, int num, string shift, decimal hr, decimal hours, decimal oTime, decimal rHours, decimal tTHours, decimal pay) : base(name, num)
{
_shiftNum = shift;
_hourlyRate = hr;
_hours = hours;
_overtime = oTime;
_trainHours = rHours;
_reqHours = tTHours;

}

public TeamLeader()
{
_shiftNum = "";
_hourlyRate = 0;
_hours = 0;
_overtime = 0;
_trainHours = 0;
_reqHours = 0;
}

public override string getData()
{
string line = "";
line += " Name: t" + this.Name + "n";
line += " Number: t" + this.Number + "n";
line += " Shift Number: t" + this.ShiftNum + "n";
line += " Hourly Rate: t" + this.HourlyRate.ToString("C") + "n";
line += " Hours Worked: t" + this.Hours + "n";
line += " Training Hours: t" + this.TrainHours.ToString() + "n";
line += " Overtime Hours: t" + (this.Hours - 40) + "n";
line += " Overtime Pay: t" + this.Overtime().ToString("C") + "n";
line += " Bonus Multiplier: t" + this.getTTrainHours().ToString("P") + "n";
line += " Bonus: t" + this.getTBonus().ToString("C") + "n";
line += " Weekly Pay: t" + this.getTPay().ToString("C");

return line;
}

public string getTeamLeaderFile()
{
string line = "";
line += this.Name + "," + this.Number + "," + this.ShiftNum + "," + this.HourlyRate.ToString() + "," + this.Hours + "," + this.TrainHours.ToString() + "," + (this.Hours - 40) + "," +
this.Overtime().ToString() + "," + this.getTTrainHours().ToString("P") + "," + this.getTBonus().ToString("C") + "," + this.getTPay().ToString();
return line;
}
}


}










share|improve this question
















I have tried if, else if, else statements, I have tried nested if statements. I have tried using variables in place of if statements. Everything functions except the Team Leader portion, there is an issue with the "TrainHours," and the repetition that it is being used, after that is corrected there is an issue with "Hours," the latest corrections was with the "GetPay()."



I have tried every different way that I can find online, and in my textbooks, but no matter what I do I get



"'System.StackOverflowException' was thrown.'"



-OR-



"'Unknown error in unknown module Exception'"



-personal gratitude removed for moderators- jeets82(edited)



Main Form:



public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void proWorker_Click(object sender, EventArgs e)
{
string pName, pShift;
decimal pOTime, pPay;

pName = pNameTxt.Text;


if (pName != "" &&
int.TryParse(pNumTxt.Text, out int pNum) &&
decimal.TryParse(pHRateTxt.Text, out decimal pHRate) &&
decimal.TryParse(pHoursTxt.Text, out decimal pHours))
{
if (dayBtn.Checked)
{
ProductionWorker pWorker1 = new ProductionWorker();
pPay = pWorker1.getPay();
pOTime = pWorker1.Overtime();

pShift = "Day";
ProductionWorker pWorker = new ProductionWorker(pName, pNum, pShift, pHRate, pHours, pOTime, pPay);

MessageBox.Show(pWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("proWorkerDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(pWorker.getProWorkerFile());

empFile.Close();
}

if (nightBtn.Checked)
{
ProductionWorker pWorker2 = new ProductionWorker();
pPay = pWorker2.getPay();
pOTime = pWorker2.Overtime();
pShift = "Night";

ProductionWorker pWorker2N = new ProductionWorker(pName, pNum, pShift, pHRate, pHours, pOTime, pPay);
MessageBox.Show(pWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("proWorkerNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(pWorker2N.getProWorkerFile());

empFile.Close();
}
}

else
{
MessageBox.Show("Enter valid Production worker information");
}

pNameTxt.Text = "";
pNumTxt.Text = "";
pHRateTxt.Text = "";
pHoursTxt.Text = "";
}

private void addEmp_Click(object sender, EventArgs e)
{
string eName;
int eNum;
eName = eNameTxt.Text;

if (Name != "" && int.TryParse(eNumTxt.Text, out eNum))
{

Employee employee = new Employee(eName, eNum);

MessageBox.Show(employee.getData());

StreamWriter empFile;
empFile = File.AppendText("EmployeeFile.txt");

Employee aEmp = new Employee();

empFile.WriteLine(employee.getEmployeeFile());

empFile.Close();
}

else
{
MessageBox.Show("Enter valid employee information.");
}


}

private void byeBtn_Click(object sender, EventArgs e)
{
this.Close();
}

private void sAddBtn_Click(object sender, EventArgs e)
{
string sName, sShift;
decimal sPay;

sName = sNameTxt.Text;

if (sName != "" &&
int.TryParse(sNumTxt.Text, out int sNum) &&
decimal.TryParse(sSalTxt.Text, out decimal sSal) &&
decimal.TryParse(sBonusTxt.Text, out decimal sBonus))
{

if (sDayBtn.Checked)
{
ShiftSupervisor sWorker1 = new ShiftSupervisor();
sPay = sWorker1.getSPay();

sShift = "Day";
ShiftSupervisor sWorker = new ShiftSupervisor(sName, sNum, sShift, sSal, sBonus, sPay);

MessageBox.Show(sWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("sWorkerDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(sWorker.getSWorkerFile());

empFile.Close();
}

if (sNightBtn.Checked)
{
ShiftSupervisor sWorker2 = new ShiftSupervisor();
sPay = sWorker2.getSPay();

sShift = "Night";
ShiftSupervisor sWorker2N = new ShiftSupervisor(sName, sNum, sShift, sSal, sBonus, sPay);
MessageBox.Show(sWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("sWorkerNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(sWorker2N.getSWorkerFile());

empFile.Close();
}

}

else
{
MessageBox.Show("Enter valid Shift Supervisor information.");
}

sNameTxt.Text = "";
sNumTxt.Text = "";
sSalTxt.Text = "";
sBonusTxt.Text = "";
}

private void addTLBtn_Click(object sender, EventArgs e)
{
string tName, tShift;
decimal tOTime, tPay;

tName = tNameTxt.Text;


if (tName != "" &&
int.TryParse(tNumTxt.Text, out int tNum) &&
decimal.TryParse(tHRateTxt.Text, out decimal tHRate) &&
decimal.TryParse(tHoursTxt.Text, out decimal tHours) &&
decimal.TryParse(tTrainTxt.Text, out decimal tTrain))
{
if (tDayBtn.Checked)
{
TeamLeader tWorker1 = new TeamLeader();
tPay = tWorker1.getTPay();
tOTime = tWorker1.Overtime();
decimal rHours = tWorker1.ReqHours;
decimal tTHours = tWorker1.TrainHours;

tShift = "Day";
TeamLeader tWorker = new TeamLeader(tName, tNum, tShift, tHRate, tHours, tOTime, rHours, tTHours, tPay);

MessageBox.Show(tWorker.getData());

StreamWriter empFile;
empFile = File.AppendText("TeamLeaderDay.txt");

Employee aEmp = new Employee();

empFile.WriteLine(tWorker.getTeamLeaderFile());

empFile.Close();
}

if (tNightBtn.Checked)
{
TeamLeader tWorker2 = new TeamLeader();
tPay = tWorker2.getTPay();
tOTime = tWorker2.Overtime();
decimal rHours = tWorker2.ReqHours;
decimal tTHours = tWorker2.TrainHours;

tShift = "Day";
TeamLeader tWorker2N = new TeamLeader(tName, tNum, tShift, tHRate, tHours, tOTime, rHours, tTHours, tPay);
MessageBox.Show(tWorker2N.getData());

StreamWriter empFile;
empFile = File.AppendText("TeamLeaderNight.txt");

Employee aEmp = new Employee();

empFile.WriteLine(tWorker2N.getTeamLeaderFile());

empFile.Close();
}
}

else
{
MessageBox.Show("Enter valid Production worker information");
}

tNameTxt.Text = "";
tNumTxt.Text = "";
tHRateTxt.Text = "";
tHoursTxt.Text = "";
tTrainTxt.Text = "";
}
}


Base Class:



class Employee
{
private string _name;
private int _number;
private string _empAddList;

public Employee(string name, int num)
{
_name = name;
_number = num;
_empAddList = name + " " + num.ToString();
}

public Employee()
{
_name = "";
_number = 0;
}

public string Name
{
get { return _name; }
set { _name = value; }
}

public int Number
{
get { return _number; }
set { _number = value; }
}

public string EmpAddList
{
get { return _empAddList; }
set { _empAddList = value; }
}

//define method to return the values
public virtual string getData()
{
string line = "";
line += " Name: tt" + this.Name + "n";
line += " Number: t" + this.Number;
return line;
}

public string getEmployeeFile()
{
string line = "";
line += this.Name + "," + this.Number;
return line;
}

}

abstract class Employee1 : Employee
{
public abstract decimal Overtime();
public abstract decimal getPay();
}


PROBLEM CLASS I have fixed almost every portion and every time I fix something it gives me a different error or StackOverflowException.



class TeamLeader : Employee
{
private string _shiftNum;
private decimal _hourlyRate;
private decimal _reqHours;
private decimal _trainHours;
private decimal _hours;
private decimal _overtime;
private decimal _oT;


public string ShiftNum
{
get { return _shiftNum; }
set
{
if (_shiftNum == "Day Shift")
{
_shiftNum = "Day";
}

else
{
_shiftNum = "Night";
}
}
}

public decimal HourlyRate
{
get { return _hourlyRate; }
set { _hourlyRate = value; }
}

public decimal Hours
{
get { return _hours; }
set { _hours = value; }
}

public decimal ReqHours
{
get { return _reqHours; }
set { _reqHours = value; }
}

public decimal TrainHours
{
get { return _trainHours; }
set { _trainHours = value; }
}

public decimal Overtime()
{
decimal oTime = 0;

if (Hours > 40)
{
_oT = Hours - 40;
oTime = (HourlyRate * 1.5m) * _oT;
}

else
{
oTime = 0;
}

return oTime;
}

public decimal getTBonus()
{
decimal tBonus = 0;
if (TrainHours <= 0 && Hours <= 0)
{ tBonus = 0; }

if (TrainHours >= (Hours * .15m))
{ tBonus = getTPay() * .15m; }

if (TrainHours >= (Hours * .1m))
{ tBonus = getTPay() * .125m; }

if (TrainHours >= (Hours * .08m))
{ tBonus = getTPay() * .05m; }

else
{ tBonus = getTPay() * .025m; }

return tBonus;
}

public decimal getTTrainHours()
{
decimal tHours = 0;
if (TrainHours <= 0 && Hours <= 0)
{ tHours = 0; }

if (TrainHours >= (Hours * .15m))
{ tHours = Hours * .15m; }

else if (TrainHours <= (Hours * .1m))
{ tHours = Hours * .125m; }

else if (TrainHours <= (Hours * .08m))
{ tHours = Hours * .05m; }

else
{ tHours = Hours * .025m; }

return tHours;
}

public decimal getTPay()
{
decimal paid = 0;

if (Hours <= 0)
{ paid = 0; }

if (Hours > 40)
{ paid = (HourlyRate * 40) + Overtime() + getTBonus(); }

else
{ paid = (Hours * HourlyRate) + getTBonus(); }

return paid;
}

public TeamLeader(string name, int num, string shift, decimal hr, decimal hours, decimal oTime, decimal rHours, decimal tTHours, decimal pay) : base(name, num)
{
_shiftNum = shift;
_hourlyRate = hr;
_hours = hours;
_overtime = oTime;
_trainHours = rHours;
_reqHours = tTHours;

}

public TeamLeader()
{
_shiftNum = "";
_hourlyRate = 0;
_hours = 0;
_overtime = 0;
_trainHours = 0;
_reqHours = 0;
}

public override string getData()
{
string line = "";
line += " Name: t" + this.Name + "n";
line += " Number: t" + this.Number + "n";
line += " Shift Number: t" + this.ShiftNum + "n";
line += " Hourly Rate: t" + this.HourlyRate.ToString("C") + "n";
line += " Hours Worked: t" + this.Hours + "n";
line += " Training Hours: t" + this.TrainHours.ToString() + "n";
line += " Overtime Hours: t" + (this.Hours - 40) + "n";
line += " Overtime Pay: t" + this.Overtime().ToString("C") + "n";
line += " Bonus Multiplier: t" + this.getTTrainHours().ToString("P") + "n";
line += " Bonus: t" + this.getTBonus().ToString("C") + "n";
line += " Weekly Pay: t" + this.getTPay().ToString("C");

return line;
}

public string getTeamLeaderFile()
{
string line = "";
line += this.Name + "," + this.Number + "," + this.ShiftNum + "," + this.HourlyRate.ToString() + "," + this.Hours + "," + this.TrainHours.ToString() + "," + (this.Hours - 40) + "," +
this.Overtime().ToString() + "," + this.getTTrainHours().ToString("P") + "," + this.getTBonus().ToString("C") + "," + this.getTPay().ToString();
return line;
}
}


}







c# .net winforms function class






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 7:16







jeets82

















asked Nov 23 '18 at 5:52









jeets82jeets82

35




35








  • 3





    Welcome to StackOverflow. There's a joke about a speak-your-weight machine, where a large person stands on it, and it says "one person at a time, please!". This question is a bit like that. Your question needs to focus on one issue. You need to provide a Minimal, Complete, and Verifiable example (for example, edit your question to remove all the commented code). Pick one exception, and show us the code when that happens; and tell us what line it happens on. I sympathise with the background info, but it's not relevant to the question: try to focus on the issue. The "how to ask" uses the phrase "talking to a busy colleague".

    – Richardissimo
    Nov 23 '18 at 6:16











  • I didn't down vote. I'm trying to help. You mentioned 2 exceptions, not just one. Your experience here will be bad if you don't learn How to ask. For example, let me offer this unrelated tip: StreamWriter is IDisposable so should be in a using block. Once you've done that, you don't need to Close it because it will be closed by the implicit Dispose as it exits the block.

    – Richardissimo
    Nov 23 '18 at 6:58











  • I'd like to clarify and apologize. I had directed that portion at @Uwe Keim who did downvote my question without explanation and removed a pre-emptive appreciation I had shown. Do you have some direction on how to better phrase my question? I will gladly try to be more direct.

    – jeets82
    Nov 23 '18 at 7:07











  • No problem: as you said yourself, we've all been there, and glad you found your answer. Don't take the down votes to heart - StackOverflow is a powerful tool; but one has to learn how to use it. There are lots of tips on the 'How to ask' page, and the MCVE page is regularly quoted, and applies here: It is all too easy to just throw a load of code at StackOverflow and say "help!", but that does not make a good question, and I fear this question strayed too much in that direction, which may have drawn the down votes. Look on meta.stackoverflow.com for info on how people use this site.Best wishes

    – Richardissimo
    Nov 23 '18 at 21:19











  • @Richardissimo I would like to thank you. It took some time. Another whole day in fact, but I learned to use the: FileStream, and: Using to achieve the IDisposable. Thank you.

    – jeets82
    Nov 25 '18 at 1:26














  • 3





    Welcome to StackOverflow. There's a joke about a speak-your-weight machine, where a large person stands on it, and it says "one person at a time, please!". This question is a bit like that. Your question needs to focus on one issue. You need to provide a Minimal, Complete, and Verifiable example (for example, edit your question to remove all the commented code). Pick one exception, and show us the code when that happens; and tell us what line it happens on. I sympathise with the background info, but it's not relevant to the question: try to focus on the issue. The "how to ask" uses the phrase "talking to a busy colleague".

    – Richardissimo
    Nov 23 '18 at 6:16











  • I didn't down vote. I'm trying to help. You mentioned 2 exceptions, not just one. Your experience here will be bad if you don't learn How to ask. For example, let me offer this unrelated tip: StreamWriter is IDisposable so should be in a using block. Once you've done that, you don't need to Close it because it will be closed by the implicit Dispose as it exits the block.

    – Richardissimo
    Nov 23 '18 at 6:58











  • I'd like to clarify and apologize. I had directed that portion at @Uwe Keim who did downvote my question without explanation and removed a pre-emptive appreciation I had shown. Do you have some direction on how to better phrase my question? I will gladly try to be more direct.

    – jeets82
    Nov 23 '18 at 7:07











  • No problem: as you said yourself, we've all been there, and glad you found your answer. Don't take the down votes to heart - StackOverflow is a powerful tool; but one has to learn how to use it. There are lots of tips on the 'How to ask' page, and the MCVE page is regularly quoted, and applies here: It is all too easy to just throw a load of code at StackOverflow and say "help!", but that does not make a good question, and I fear this question strayed too much in that direction, which may have drawn the down votes. Look on meta.stackoverflow.com for info on how people use this site.Best wishes

    – Richardissimo
    Nov 23 '18 at 21:19











  • @Richardissimo I would like to thank you. It took some time. Another whole day in fact, but I learned to use the: FileStream, and: Using to achieve the IDisposable. Thank you.

    – jeets82
    Nov 25 '18 at 1:26








3




3





Welcome to StackOverflow. There's a joke about a speak-your-weight machine, where a large person stands on it, and it says "one person at a time, please!". This question is a bit like that. Your question needs to focus on one issue. You need to provide a Minimal, Complete, and Verifiable example (for example, edit your question to remove all the commented code). Pick one exception, and show us the code when that happens; and tell us what line it happens on. I sympathise with the background info, but it's not relevant to the question: try to focus on the issue. The "how to ask" uses the phrase "talking to a busy colleague".

– Richardissimo
Nov 23 '18 at 6:16





Welcome to StackOverflow. There's a joke about a speak-your-weight machine, where a large person stands on it, and it says "one person at a time, please!". This question is a bit like that. Your question needs to focus on one issue. You need to provide a Minimal, Complete, and Verifiable example (for example, edit your question to remove all the commented code). Pick one exception, and show us the code when that happens; and tell us what line it happens on. I sympathise with the background info, but it's not relevant to the question: try to focus on the issue. The "how to ask" uses the phrase "talking to a busy colleague".

– Richardissimo
Nov 23 '18 at 6:16













I didn't down vote. I'm trying to help. You mentioned 2 exceptions, not just one. Your experience here will be bad if you don't learn How to ask. For example, let me offer this unrelated tip: StreamWriter is IDisposable so should be in a using block. Once you've done that, you don't need to Close it because it will be closed by the implicit Dispose as it exits the block.

– Richardissimo
Nov 23 '18 at 6:58





I didn't down vote. I'm trying to help. You mentioned 2 exceptions, not just one. Your experience here will be bad if you don't learn How to ask. For example, let me offer this unrelated tip: StreamWriter is IDisposable so should be in a using block. Once you've done that, you don't need to Close it because it will be closed by the implicit Dispose as it exits the block.

– Richardissimo
Nov 23 '18 at 6:58













I'd like to clarify and apologize. I had directed that portion at @Uwe Keim who did downvote my question without explanation and removed a pre-emptive appreciation I had shown. Do you have some direction on how to better phrase my question? I will gladly try to be more direct.

– jeets82
Nov 23 '18 at 7:07





I'd like to clarify and apologize. I had directed that portion at @Uwe Keim who did downvote my question without explanation and removed a pre-emptive appreciation I had shown. Do you have some direction on how to better phrase my question? I will gladly try to be more direct.

– jeets82
Nov 23 '18 at 7:07













No problem: as you said yourself, we've all been there, and glad you found your answer. Don't take the down votes to heart - StackOverflow is a powerful tool; but one has to learn how to use it. There are lots of tips on the 'How to ask' page, and the MCVE page is regularly quoted, and applies here: It is all too easy to just throw a load of code at StackOverflow and say "help!", but that does not make a good question, and I fear this question strayed too much in that direction, which may have drawn the down votes. Look on meta.stackoverflow.com for info on how people use this site.Best wishes

– Richardissimo
Nov 23 '18 at 21:19





No problem: as you said yourself, we've all been there, and glad you found your answer. Don't take the down votes to heart - StackOverflow is a powerful tool; but one has to learn how to use it. There are lots of tips on the 'How to ask' page, and the MCVE page is regularly quoted, and applies here: It is all too easy to just throw a load of code at StackOverflow and say "help!", but that does not make a good question, and I fear this question strayed too much in that direction, which may have drawn the down votes. Look on meta.stackoverflow.com for info on how people use this site.Best wishes

– Richardissimo
Nov 23 '18 at 21:19













@Richardissimo I would like to thank you. It took some time. Another whole day in fact, but I learned to use the: FileStream, and: Using to achieve the IDisposable. Thank you.

– jeets82
Nov 25 '18 at 1:26





@Richardissimo I would like to thank you. It took some time. Another whole day in fact, but I learned to use the: FileStream, and: Using to achieve the IDisposable. Thank you.

– jeets82
Nov 25 '18 at 1:26












2 Answers
2






active

oldest

votes


















4














The problem is in TeamLeader::getData()



getTBonus() is calling getTPay() which is calling getTBonus() again causing an infinite loop, which will throw the StackOverflowException.



You might try using if...else if in those methods instead of just if.



public decimal getTBonus()
{
decimal tBonus = 0;
if (TrainHours <= 0 && Hours <= 0)
{ tBonus = 0; }

else if (TrainHours >= (Hours * .15m))
{ tBonus = getTPay() * .15m; }

else if (TrainHours >= (Hours * .1m))
{ tBonus = getTPay() * .125m; }

else if (TrainHours >= (Hours * .08m))
{ tBonus = getTPay() * .05m; }

else
{ tBonus = getTPay() * .025m; }

return tBonus;
}

public decimal getTPay()
{
decimal paid = 0;

if (Hours <= 0)
{ paid = 0; }

else if (Hours > 40)
{ paid = (HourlyRate * 40) + Overtime() + getTBonus(); }

else
{ paid = (Hours * HourlyRate) + getTBonus(); }

return paid;
}





share|improve this answer


























  • The infinite loop might be fixable by changing "get T bonus amount" to "get T bonus percentage" (which doesn't need to call getTPay)

    – Hans Kesting
    Nov 23 '18 at 7:07











  • The problem persists and just pops up in a different place. This time it threw the same exception -System.StackOverflowException HResult=0x800703E9 Message=Exception of type 'System.StackOverflowException' was thrown. at the public decimal Hours { get { return _hours; } set { _hours = value; } }

    – jeets82
    Nov 23 '18 at 7:11





















0














I was able to solve the issue by removing the getBonus() from the getPay() method. After I did that I added a new variable that added them together in the getData() method. This worked. Now I just need to figure out why my TrainHours will not populate. Thank you all that was helpful in guiding me to the answer.



decimal weeklyPay = getTBonus() + getTPay();



line += " Weekly Pay: t" + weeklyPay.ToString("C");






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441268%2fstill-learning-system-stackoverflowexception-was-thrown%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    The problem is in TeamLeader::getData()



    getTBonus() is calling getTPay() which is calling getTBonus() again causing an infinite loop, which will throw the StackOverflowException.



    You might try using if...else if in those methods instead of just if.



    public decimal getTBonus()
    {
    decimal tBonus = 0;
    if (TrainHours <= 0 && Hours <= 0)
    { tBonus = 0; }

    else if (TrainHours >= (Hours * .15m))
    { tBonus = getTPay() * .15m; }

    else if (TrainHours >= (Hours * .1m))
    { tBonus = getTPay() * .125m; }

    else if (TrainHours >= (Hours * .08m))
    { tBonus = getTPay() * .05m; }

    else
    { tBonus = getTPay() * .025m; }

    return tBonus;
    }

    public decimal getTPay()
    {
    decimal paid = 0;

    if (Hours <= 0)
    { paid = 0; }

    else if (Hours > 40)
    { paid = (HourlyRate * 40) + Overtime() + getTBonus(); }

    else
    { paid = (Hours * HourlyRate) + getTBonus(); }

    return paid;
    }





    share|improve this answer


























    • The infinite loop might be fixable by changing "get T bonus amount" to "get T bonus percentage" (which doesn't need to call getTPay)

      – Hans Kesting
      Nov 23 '18 at 7:07











    • The problem persists and just pops up in a different place. This time it threw the same exception -System.StackOverflowException HResult=0x800703E9 Message=Exception of type 'System.StackOverflowException' was thrown. at the public decimal Hours { get { return _hours; } set { _hours = value; } }

      – jeets82
      Nov 23 '18 at 7:11


















    4














    The problem is in TeamLeader::getData()



    getTBonus() is calling getTPay() which is calling getTBonus() again causing an infinite loop, which will throw the StackOverflowException.



    You might try using if...else if in those methods instead of just if.



    public decimal getTBonus()
    {
    decimal tBonus = 0;
    if (TrainHours <= 0 && Hours <= 0)
    { tBonus = 0; }

    else if (TrainHours >= (Hours * .15m))
    { tBonus = getTPay() * .15m; }

    else if (TrainHours >= (Hours * .1m))
    { tBonus = getTPay() * .125m; }

    else if (TrainHours >= (Hours * .08m))
    { tBonus = getTPay() * .05m; }

    else
    { tBonus = getTPay() * .025m; }

    return tBonus;
    }

    public decimal getTPay()
    {
    decimal paid = 0;

    if (Hours <= 0)
    { paid = 0; }

    else if (Hours > 40)
    { paid = (HourlyRate * 40) + Overtime() + getTBonus(); }

    else
    { paid = (Hours * HourlyRate) + getTBonus(); }

    return paid;
    }





    share|improve this answer


























    • The infinite loop might be fixable by changing "get T bonus amount" to "get T bonus percentage" (which doesn't need to call getTPay)

      – Hans Kesting
      Nov 23 '18 at 7:07











    • The problem persists and just pops up in a different place. This time it threw the same exception -System.StackOverflowException HResult=0x800703E9 Message=Exception of type 'System.StackOverflowException' was thrown. at the public decimal Hours { get { return _hours; } set { _hours = value; } }

      – jeets82
      Nov 23 '18 at 7:11
















    4












    4








    4







    The problem is in TeamLeader::getData()



    getTBonus() is calling getTPay() which is calling getTBonus() again causing an infinite loop, which will throw the StackOverflowException.



    You might try using if...else if in those methods instead of just if.



    public decimal getTBonus()
    {
    decimal tBonus = 0;
    if (TrainHours <= 0 && Hours <= 0)
    { tBonus = 0; }

    else if (TrainHours >= (Hours * .15m))
    { tBonus = getTPay() * .15m; }

    else if (TrainHours >= (Hours * .1m))
    { tBonus = getTPay() * .125m; }

    else if (TrainHours >= (Hours * .08m))
    { tBonus = getTPay() * .05m; }

    else
    { tBonus = getTPay() * .025m; }

    return tBonus;
    }

    public decimal getTPay()
    {
    decimal paid = 0;

    if (Hours <= 0)
    { paid = 0; }

    else if (Hours > 40)
    { paid = (HourlyRate * 40) + Overtime() + getTBonus(); }

    else
    { paid = (Hours * HourlyRate) + getTBonus(); }

    return paid;
    }





    share|improve this answer















    The problem is in TeamLeader::getData()



    getTBonus() is calling getTPay() which is calling getTBonus() again causing an infinite loop, which will throw the StackOverflowException.



    You might try using if...else if in those methods instead of just if.



    public decimal getTBonus()
    {
    decimal tBonus = 0;
    if (TrainHours <= 0 && Hours <= 0)
    { tBonus = 0; }

    else if (TrainHours >= (Hours * .15m))
    { tBonus = getTPay() * .15m; }

    else if (TrainHours >= (Hours * .1m))
    { tBonus = getTPay() * .125m; }

    else if (TrainHours >= (Hours * .08m))
    { tBonus = getTPay() * .05m; }

    else
    { tBonus = getTPay() * .025m; }

    return tBonus;
    }

    public decimal getTPay()
    {
    decimal paid = 0;

    if (Hours <= 0)
    { paid = 0; }

    else if (Hours > 40)
    { paid = (HourlyRate * 40) + Overtime() + getTBonus(); }

    else
    { paid = (Hours * HourlyRate) + getTBonus(); }

    return paid;
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 23 '18 at 7:18









    Uwe Keim

    27.5k31130210




    27.5k31130210










    answered Nov 23 '18 at 6:17









    Simply GedSimply Ged

    2,55321421




    2,55321421













    • The infinite loop might be fixable by changing "get T bonus amount" to "get T bonus percentage" (which doesn't need to call getTPay)

      – Hans Kesting
      Nov 23 '18 at 7:07











    • The problem persists and just pops up in a different place. This time it threw the same exception -System.StackOverflowException HResult=0x800703E9 Message=Exception of type 'System.StackOverflowException' was thrown. at the public decimal Hours { get { return _hours; } set { _hours = value; } }

      – jeets82
      Nov 23 '18 at 7:11





















    • The infinite loop might be fixable by changing "get T bonus amount" to "get T bonus percentage" (which doesn't need to call getTPay)

      – Hans Kesting
      Nov 23 '18 at 7:07











    • The problem persists and just pops up in a different place. This time it threw the same exception -System.StackOverflowException HResult=0x800703E9 Message=Exception of type 'System.StackOverflowException' was thrown. at the public decimal Hours { get { return _hours; } set { _hours = value; } }

      – jeets82
      Nov 23 '18 at 7:11



















    The infinite loop might be fixable by changing "get T bonus amount" to "get T bonus percentage" (which doesn't need to call getTPay)

    – Hans Kesting
    Nov 23 '18 at 7:07





    The infinite loop might be fixable by changing "get T bonus amount" to "get T bonus percentage" (which doesn't need to call getTPay)

    – Hans Kesting
    Nov 23 '18 at 7:07













    The problem persists and just pops up in a different place. This time it threw the same exception -System.StackOverflowException HResult=0x800703E9 Message=Exception of type 'System.StackOverflowException' was thrown. at the public decimal Hours { get { return _hours; } set { _hours = value; } }

    – jeets82
    Nov 23 '18 at 7:11







    The problem persists and just pops up in a different place. This time it threw the same exception -System.StackOverflowException HResult=0x800703E9 Message=Exception of type 'System.StackOverflowException' was thrown. at the public decimal Hours { get { return _hours; } set { _hours = value; } }

    – jeets82
    Nov 23 '18 at 7:11















    0














    I was able to solve the issue by removing the getBonus() from the getPay() method. After I did that I added a new variable that added them together in the getData() method. This worked. Now I just need to figure out why my TrainHours will not populate. Thank you all that was helpful in guiding me to the answer.



    decimal weeklyPay = getTBonus() + getTPay();



    line += " Weekly Pay: t" + weeklyPay.ToString("C");






    share|improve this answer




























      0














      I was able to solve the issue by removing the getBonus() from the getPay() method. After I did that I added a new variable that added them together in the getData() method. This worked. Now I just need to figure out why my TrainHours will not populate. Thank you all that was helpful in guiding me to the answer.



      decimal weeklyPay = getTBonus() + getTPay();



      line += " Weekly Pay: t" + weeklyPay.ToString("C");






      share|improve this answer


























        0












        0








        0







        I was able to solve the issue by removing the getBonus() from the getPay() method. After I did that I added a new variable that added them together in the getData() method. This worked. Now I just need to figure out why my TrainHours will not populate. Thank you all that was helpful in guiding me to the answer.



        decimal weeklyPay = getTBonus() + getTPay();



        line += " Weekly Pay: t" + weeklyPay.ToString("C");






        share|improve this answer













        I was able to solve the issue by removing the getBonus() from the getPay() method. After I did that I added a new variable that added them together in the getData() method. This worked. Now I just need to figure out why my TrainHours will not populate. Thank you all that was helpful in guiding me to the answer.



        decimal weeklyPay = getTBonus() + getTPay();



        line += " Weekly Pay: t" + weeklyPay.ToString("C");







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 7:27









        jeets82jeets82

        35




        35






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441268%2fstill-learning-system-stackoverflowexception-was-thrown%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'