Time Addition

Discussion in 'Questions (Windows Mobile)' started by busboy, Oct 1, 2007.

  1. busboy

    busboy New Member

    Is it possible to add or subtract large time values in basic4ppc.
    For example 32:10 + 40:10 = 72:20
    If it is possible how do you go about doing it? If not what other alternate do I have beside converting it to fractions?

    Thanks
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. busboy

    busboy New Member

    Yes. In fact, would it be possible to add 140:34 i.e140mins and 34 sec, to say 12:10 to get 152:44.

    I have read the tutorial some time back but have still not figured a way to do this!

    Thanks for your quick reply
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You will need to parse the strings:
    Code:
    Sub App_Start
        
    Msgbox(MSAdd("123:33","40:35"))
    End Sub

    Sub MSAdd(x,y)
        i = StrIndexOf(x,
    ":",0)
        
    If i = -1 Then Return "00:00"
        m1 = SubString(x,
    0,i)
        s1 = SubString(x,i+
    1,StrLength(x)-i-1)
        i = StrIndexOf(y,
    ":",0)
        
    If i = -1 Then Return "00:00"
        m2 = SubString(y,
    0,i)
        s2 = SubString(y,i+
    1,StrLength(y)-i-1)
        s = s1 + s2
        m = m1 + m2 + Int(s/
    60)
        
    Return m & ":" & Format((s Mod 60),"D2")
    End Sub
     
Loading...