Home All Groups Group Topic Archive Search About

Calculating Time in VB .Net

Author
30 Jun 2005 3:09 AM
Brian
I'm learning to program with VB .Net.  I'm trying to write a program that
will calculate jogging time.  I have Text boxes for Distance1, Distance2,
Speed1, Speed2, Time1, Time2, and Total Time.  For example, say I run 2 miles
at 8mph (7:30 minute miles) and 1 mile at 7.5mph (8 minute miles).  I enter 2
in Distance1, 1 in Distance2, 8 in Speed1, and 7.5 in Speed2.  I can
calculate in decimal (10.25, 10.5, 10.75 minutes, etc.)  How would I
calculate the three times in minutes and seconds (10:15. 10:30, 10:45)? 
Thanks!

Author
30 Jun 2005 6:26 AM
Cor Ligthert
Brian,

This sounds like a student question.

Basicly you calculate it in the same way as on a piece of paper, however you
use than some code to do that, which differs not much from that.

Cor
Author
30 Jun 2005 8:55 AM
Armin Zingler
"Brian" <Br***@discussions.microsoft.com> schrieb
> I'm learning to program with VB .Net.  I'm trying to write a program
> that will calculate jogging time.  I have Text boxes for Distance1,
> Distance2, Speed1, Speed2, Time1, Time2, and Total Time.  For
> example, say I run 2 miles at 8mph (7:30 minute miles) and 1 mile at
> 7.5mph (8 minute miles).  I enter 2 in Distance1, 1 in Distance2, 8
> in Speed1, and 7.5 in Speed2.  I can calculate in decimal (10.25,
> 10.5, 10.75 minutes, etc.)  How would I calculate the three times in
> minutes and seconds (10:15. 10:30, 10:45)? Thanks!
>


Have a look at the very helpful DateTime (called Date in VB.Net but they are
identic) and TimeSpan types and there members.

Armin
Author
30 Jun 2005 3:26 PM
Brian
"Cor Ligthert" wrote:

> Brian,
>
> This sounds like a student question.
>
> Basicly you calculate it in the same way as on a piece of paper, however you
> use than some code to do that, which differs not much from that.
>
> Cor

No, not a student.  Thanks for asking though.  Just a database analyst who
likes to run and trying to add some programming by starting off with
something really basic.  Have to start small you know.

Show quoteHide quote
"Armin Zingler" wrote:

> "Brian" <Br***@discussions.microsoft.com> schrieb
> > I'm learning to program with VB .Net.  I'm trying to write a program
> > that will calculate jogging time.  I have Text boxes for Distance1,
> > Distance2, Speed1, Speed2, Time1, Time2, and Total Time.  For
> > example, say I run 2 miles at 8mph (7:30 minute miles) and 1 mile at
> > 7.5mph (8 minute miles).  I enter 2 in Distance1, 1 in Distance2, 8
> > in Speed1, and 7.5 in Speed2.  I can calculate in decimal (10.25,
> > 10.5, 10.75 minutes, etc.)  How would I calculate the three times in
> > minutes and seconds (10:15. 10:30, 10:45)? Thanks!
> >
>
>
> Have a look at the very helpful DateTime (called Date in VB.Net but they are
> identic) and TimeSpan types and there members.
>
> Armin
>
>

Thanks Armin!  Will do.
Author
30 Jun 2005 5:08 PM
Cor Ligthert
Brian,

Than in addition to Armin is TimeSpan what you need and than the method
"FromSeconds" or an equivalent. I write that because I have seen that these
ones are easily missed.

I hope this helps,

Cor