Adding Times in VB.NET
Thread Starter
Join Date: Jan 2000
Location: Dublin, Ireland
Posts: 19
Likes: 0
Received 0 Likes
on
0 Posts
Adding Times in VB.NET
Hi,
I am trying to add times when I press "Button1" to sum "Textbox1" and "Textbox2" the result to display in "Label1"
e.g. Textbox1 = 12:03 and Textbox2 =02:03 I want Ans. 14:06
Textbox1 = 22:03 and Textbox2 =05:20 I want Ans. 03:23
This is in VB.NET
Can anyone show me the code.
Thanks.
I am trying to add times when I press "Button1" to sum "Textbox1" and "Textbox2" the result to display in "Label1"
e.g. Textbox1 = 12:03 and Textbox2 =02:03 I want Ans. 14:06
Textbox1 = 22:03 and Textbox2 =05:20 I want Ans. 03:23
This is in VB.NET
Can anyone show me the code.
Thanks.
Per Ardua ad Astraeus
Join Date: Mar 2000
Location: UK
Posts: 18,579
Likes: 0
Received 0 Likes
on
0 Posts
Cannot help with VB code, but generally it goes:
'If LabelY>X then LabelY=LabelY-X'
In the case of hours, X=24. You'll need to split the minutes out as well (maybe use 'INT' or 'Left/RightString' depending on how VB codes) and then X will be 60. They need adding back in at the end. Might be easier just to work in minutes until the end?
Getting the 'zeroes' in front of the numbers is a whole new ball game....................
'If LabelY>X then LabelY=LabelY-X'
In the case of hours, X=24. You'll need to split the minutes out as well (maybe use 'INT' or 'Left/RightString' depending on how VB codes) and then X will be 60. They need adding back in at the end. Might be easier just to work in minutes until the end?
Getting the 'zeroes' in front of the numbers is a whole new ball game....................
Thread Starter
Join Date: Jan 2000
Location: Dublin, Ireland
Posts: 19
Likes: 0
Received 0 Likes
on
0 Posts
Ta, BOAC
That code is ok for things like Excel and VBA. But .NET is different. I'm getting lost somewhere in converting from data type 'string' which is the only thing a textbox will accept in .NET into 'datetime'
I'll keep hunting.
That code is ok for things like Excel and VBA. But .NET is different. I'm getting lost somewhere in converting from data type 'string' which is the only thing a textbox will accept in .NET into 'datetime'
I'll keep hunting.
Per Ardua ad Astraeus
Join Date: Mar 2000
Location: UK
Posts: 18,579
Likes: 0
Received 0 Likes
on
0 Posts
OK- my last go since I cannot guess exactly what you are trying to do!
If you just want to add two data strings representing time, why bother with 'datetime'? Perhaps if you outlined the task someone could help?
If you just want to add two data strings representing time, why bother with 'datetime'? Perhaps if you outlined the task someone could help?
Join Date: Nov 2003
Location: In la la land.......
Age: 45
Posts: 174
Likes: 0
Received 0 Likes
on
0 Posts
overwing
you need to work with a timespan difference.. create a datetime object for each time then get the difference between the 2 then add the difference to the first one
article here in c# on datetime differences but exact principle applies to vb.net
http://articles.techrepublic.com.com...1-5760752.html
you need to work with a timespan difference.. create a datetime object for each time then get the difference between the 2 then add the difference to the first one
article here in c# on datetime differences but exact principle applies to vb.net
http://articles.techrepublic.com.com...1-5760752.html