Try something like this (this is untested code, so you may need to tweak it a bit):
private void GoButt_Click(object sender, RoutedEventArgs e)
{
double VL;
double VA;
double VTS;
double GypScrew0;
if (double.TryParse(LO.Text, out VL) &&
double.TryParse(AO.Text, out VA) &&
GSL.SelectedIndex >= 0 &&
CSL.SelectedIndex >= 0)
{
VTS = VL * VA;
TSF.Text = VTS.ToString();
TMS.Text = (VL * 12 / 16).ToString();
TMT.Text = (VL * 2 / 10).ToString();
TMSc.Text = (VL * 12 / 16 * 4).ToString();
TGB.Text = CalcTGB(VTS, GSL.SelectedIndex, CSL.SelectedIndex).ToString();
}
else
{
throw new Exception("Something bad happened on the way to the Bijou Theater");
}
}
private double CalcTGB(double vts, int gslIndex, int cslIndex)
{
double result = 0d;
#if DEBUG
int divider = 32 + (4 * cslIndex);
int multiplier = cslIndex + 1;
result = vts / (double)((divider * multiplier));
#else
result = vts / (double)((32 + (4 * cslIndex)) * (cslIndex + 1));
#endif
return result;
}
EDIT ===============
My method allows you to step through it in the debugger to make sure the multiplier and divider are what you expect them to be.
Final note - you shoud realy use
double.TryParse
(instead of
Convert.ToDouble
) when you're converting user-specified data to numeric values. This will eliminate the need for the
try/catch
block.
EDIT ===============
I modified my example to use
TryParse
instead of
Convert.ToDouble
.