Wikiposts
Search
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

Thread Tools
 
Search this Thread
 
Old 3rd Sep 2006, 11:54
  #1 (permalink)  
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.
overwing is offline  
Old 3rd Sep 2006, 12:25
  #2 (permalink)  
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....................
BOAC is offline  
Old 3rd Sep 2006, 14:34
  #3 (permalink)  
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.
overwing is offline  
Old 3rd Sep 2006, 18:20
  #4 (permalink)  
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?
BOAC is offline  
Old 3rd Sep 2006, 18:30
  #5 (permalink)  
 
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
zoink is offline  
Old 5th Sep 2006, 09:45
  #6 (permalink)  
Thread Starter
 
Join Date: Jan 2000
Location: Dublin, Ireland
Posts: 19
Likes: 0
Received 0 Likes on 0 Posts
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  

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



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

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