What you have there should work - but I'd suggest that you don't use Convert.ToXXX and use TryParse instead:
private void btnCalculate_Click(object sender, EventArgs e)
{
int patId;
if (!int.TryParse(txtPatientId.Text, out patId))
{
MessageBox.Show("Please enter a valid Patient ID");
return;
}
int patWeight;
if (!int.TryParse(txtWeight.Text, out patWeight))
{
MessageBox.Show("Please enter a valid Patient Weight");
return;
}
Intake intake = new Intake(txtName.Text, patId, patWeight);
txtProtein.Text = intake.GetProteinIntake().ToString();
}
You may find that works.
And please: never "swallow" exceptions - it makes it very hard to debug code when you do that as you don't know when something fails. Report it to the user, or log it for later analysis - but never just swallow it and move on.
And if you are going to work with multiplying numbers by 0.86, I'd strongly suggest you use double values instead of integers.
"I know of the different class level variables I believe, public and private, and
I am trying to take the information from the add patient form to a list box (which I can not post at the moment as I am at work)."
Ok - so look at what Matt suggests in Solution 2 - it's all good ideas.
If you are adding the new patient to a list box in a different form, then you either want to return the new patient as a class instance via a property, and let the previous form (which I assume has the list box) deal with displaying it.
That's not too bad - verify the text boxes as above, and use a class level Patient class to return the new instance - remove the "Intake" class and create a Patient one instead.
then
public Patient { get; private set; }
and your click does the validation and then:
Patient = new Patient(txtName.Text, patId, patWeight);
And closes the form, returning DialogResult.OK
The parent form then collects the info:
frmNewPatient fnp = new frmNewPatient();
if (fnp.ShowDialog() == DialogResult.OK)
{
Patient theNewGuy = fnp.Patient;
... display the new patient in the Listbox ...
}
That way, you are passing around the info you need, instead of creating a class to deal with a tiny bit of fairly irrelevant patient info!
Make any sense?