Notices
Computer/Internet Issues & Troubleshooting Anyone with questions about the terribly complex world of computers or the internet should try here. NOT FOR REPORTING ISSUES WITH PPRuNe FORUMS! Please use the subforum "PPRuNe Problems or Queries."

Adding Times in VB.NET

Old 3rd September 2006 | 11:54
  #1 (permalink)  
Thread Starter
 
Joined: Jan 2000
Posts: 19
Likes: 0
From: Dublin, Ireland
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.
overwing is offline  
Reply
Old 3rd September 2006 | 12:25
  #2 (permalink)  
Per Ardua ad Astraeus
 
Joined: Mar 2000
Posts: 18,575
Likes: 4
From: UK
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....................
BOAC is offline  
Reply
Old 3rd September 2006 | 14:34
  #3 (permalink)  
Thread Starter
 
Joined: Jan 2000
Posts: 19
Likes: 0
From: Dublin, Ireland
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.
overwing is offline  
Reply
Old 3rd September 2006 | 18:20
  #4 (permalink)  
Per Ardua ad Astraeus
 
Joined: Mar 2000
Posts: 18,575
Likes: 4
From: UK
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?
BOAC is offline  
Reply
Old 3rd September 2006 | 18:30
  #5 (permalink)  
 
Joined: Nov 2003
Posts: 174
Likes: 0
From: In la la land.......
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
zoink is offline  
Reply
Old 5th September 2006 | 09:45
  #6 (permalink)  
Thread Starter
 
Joined: Jan 2000
Posts: 19
Likes: 0
From: Dublin, Ireland
It's the Timespan that fixed it.

Textbox1.text with StringToDateConversion function
then .add to (textbox2) with Textbox2 as timespan

Thanks guys,
overwing is offline  
Reply

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Thread Tools
Search this Thread

Contact Us - Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service

Copyright © 2026 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.