Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASM
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = Format(Now, "HH:mm:ss:fff") ' start button
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox2.Text = Format(Now, "HH:mm:ss:fff") ' end button
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'subtract button
        TextBox3.Text = TextBox2.Text - TextBox1.Text
    End Sub
End Class


for the above code the following error is coming.


Conversion from string "12:00:03:554" to type 'Double' is not valid.
Posted

1 solution

Do not format string for start and end button. Use Date.Now with the date and time.
To be able to get time difference, use DateDiff[^] function.

Another way is to use TimeSpan[^] structure.
 
Share this answer
 
v2
Comments
dipankarnalui 4-Mar-15 2:50am    
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Dim x As Date

Dim y As Date

x = DateTime.Now
TextBox1.Text = x

System.Threading.Thread.Sleep(5000)

y = DateTime.Now
TextBox2.Text = y
Dim SecondsDifference As Integer

SecondsDifference = DateDiff(DateInterval.Second, x, y)

TextBox3.Text = SecondsDifference.ToString()


End Sub


i dnt want TextBox1.Text = 04-Mar-15 1:11:59 PM this format. i want TextBox1.Text =1:11:59:300 in this format. for text box 2 also same format .. and the output(textbox3) also in same format
dipankarnalui 4-Mar-15 3:05am    
i want to remove AM/PM and date .. only time hh:mm:ss:mm is needed and the difference between two times also will be in the same format hh:mm:ss:mm.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900