[Solved] vb.net timeadding from two textbox

[ad_1]

  1. Split the strings in the TextBoxes into an array. The first element will contain the hours and the second element will contain the minutes. The c following the split character tells the compiler this is a char not a string.
  2. Use the constructor of the TimeSpan structure to create TimeSpans. The constructor takes 3 arguments, Hours as Integer, Minutes as Integer and Seconds as Integer.
  3. Finally, we can do the addition.
  4. Then display the result using .ToString with a format string. The \ is and escape character so it doesn’t think the : is something else.
 Private Sub GetTotalTime()
            Dim parseTime1() As String = TxtDTEAP.Text.Split(":"c)
            Dim parseTime2() As String = TxtWTEAP.Text.Split(":"c)
            Dim dt As TimeSpan = New TimeSpan(CInt(parseTime1(0)), CInt(parseTime1(1)), 0)
            Dim wt As TimeSpan = New TimeSpan(CInt(parseTime2(0)), CInt(parseTime2(1)), 0)
            Dim result As TimeSpan = dt + wt
            TxtTRTEAP.Text = result.ToString("h\:mm")
    End Sub

0

[ad_2]

solved vb.net timeadding from two textbox