Results 1 to 4 of 4

Thread: Add Seconds Too

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Unhappy

    The following code takes the time from text1.text and text2.text and adds them up and places the new time in text3.text....it even notices that if minutes are more then 60 to add it to the hour section....now i need this code to do the same with the seconds.....so instead of 2:30 and 2:30 equals 5:00 I need 2:30:30 and 2:30:30 which would equal 5:01...got me? Heres the code
    a=timevalue(text1)
    b=timevalue(text2)
    c=minute(a)
    d=minute(b)
    text3=hour(a)+hour _(b)& ":" & c + d
    if (c+d) >=60 then
    m=(hour(a) + hour _(b) + 1)
    n=(c+d)-60
    text3=m & ":" & n
    End if

    In the form load event add the following code:

    Text1="2:30"
    Text2="3:30"


    -RaY
    VB .Net 2010 (Ultimate)

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Question I get a error

    Expected: New or Interger or Long Or Single Or Double Or Currency or String or Varient or identifer.

    and on the first line it highlightes the last "Date"

    Dim Date1, Date2 As Date <---
    -RaY
    VB .Net 2010 (Ultimate)

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb TimeValue Function

    You only need the TimeValue function to do it.

    Assume:
    • T1 is the text from Text1
    • T2 is the text from Text2
    • T3 is the result to Text3


    Code:
    Dim T1$, T2$, T3$
    T1 = "2:30:30"
    T2 = "3:30:30"
    T3 = Format(TimeValue(T1) + TimeValue(T2), "HH:MM:SS")


  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Thanks a lot

    Dood, that one hit the spot. Thanks a lot, i been going crazy with the code i had.
    -RaY
    VB .Net 2010 (Ultimate)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width