[Mono-list] Porting a spreadsheet to C#

Ryan Boggs rmboggs at gmail.com
Sun Aug 28 14:32:20 EDT 2011


Hi,

Please see inline message below...

On Sun, Aug 28, 2011 at 10:49 AM, Paul F. Johnson
<paul at all-the-johnsons.co.uk> wrote:
> Hi,
>
> I'm almost done porting a time of death calculator based on the Henssge
> Monogram spreadsheet[1].
>
> I've got just about all of it done, but am having a shed load of
> problems with the final step - the final calculation. The code I have so
> far for the calculation is this
>
>        private void calctod(DateTime death)
>        {
>            DateTime newdeath = death;
>            double ta = Convert.ToDouble(surroundtemp.Text);
>            double tr = Convert.ToDouble(bodytemp.Text);
>            double m = Convert.ToDouble(weight.Text);
>            double factor;
>            bool t = ta <= 23 ? true : false;
>            calculateCandB(ta, tr, m);
>            calculateCorrections(t);
>            calculateIterations(t);
>            factor = correctionfactor();
>            double h, mi;
>            h = (-cas * factor);
>            mi = -(((cas - Convert.ToInt32(cas)) * 100) / 1.6666) *
> factor + h;
>            newdeath.AddHours(h).AddMinutes(mi);
It may be me not reading this correctly but the line above is not
doing anything to the "newdeath" variable since the
.Add{Hours,Minutes} functions don't affect the instance.  They return
a new DateTime object.  You probably want to do something like:

newdeath = death.AddHours(h).AddMinutes(mi);

I'm not sure if this will solve your initial problem but it is the
first thing that jumps out at me.

Hope it helps.

>            TimeSpan calced = death.Subtract(newdeath);
>            DateTime todead = death.Subtract(calced);
>            tod(todead.TimeOfDay.ToString(),
> todead.Date.ToShortDateString());
>        }
>
> The numbers being returned from the calculate methods are giving me the
> same result as I get from the spreadsheet, so they're fine.
>
> The problem seems to be in trying to parse the Excel =TIME for the time
> of death. The calculations for mi is a literal conversion of the =TIME
> equation.
>
> Can anyone shed any light on where I'm going wrong as this is driving me
> somewhat insane!
>
> Thanks
>
> Paul
> [1] www.all-the-johnsons.co.uk/tod/henssge.xls
> [2] www.all-the-johnsons.co.uk/tod/Henssge.zip <- source code
>
> --
> Vertraue mir, ich weiss, was ich mache...
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
Thanks,
Ryan


More information about the Mono-list mailing list