Hi guys,

I am programming a page that test the speed of customer's typing in the page. So what I did is to save the current time in page loading event and in the another page it will subtract the time that came from the previous page and display it.So, when the customer pressed at the button when finished it will lead to another page that display the time spent in typing so he know his speed in typing.

The code of the first page:

Public Partial Class WebForm1
    Inherits System.Web.UI.Page
    Dim H As String
    Dim M As String
    Dim S As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        H = Date.Now.Hour.ToString
        M = Date.Now.Minute.ToString
        S = Date.Now.Second.ToString
    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Response.Redirect("Check.aspx?H=" & H & "&M=" & M & "&S=" & S)
    End Sub
End Class

The code of the second page:

Public Partial Class Check
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim H As String = Request.QueryString("H")
        Dim M As String = Request.QueryString("M")
        Dim S As String = Request.QueryString("S")
        Dim H2 As String = TimeOfDay.Hour
        Dim M2 As String = TimeOfDay.Minute
        Dim S2 As String = TimeOfDay.Second
        Label1.Text = Str(Int32.Parse(S2)) & "-" & Str(Int32.Parse(S)) & "=" & Str(Int32.Parse(S2) - Int32.Parse(S))
    End Sub
End Class

The output after 10 seconds (for example) of typing and pressing the finish button:
0
that's it.....

The problem is the first must save the current time but it save the time when I pressed the finish button. When this time goes to the second page it will subtract the current time with the time of previous time and it equals to zero.
for example:
suppose I opened the page at the time 10:30:10, and I have typed in the fields and finished at 10:30:30.
So, H,M and S must equal to these values:
H=10
M=30
S=10
and at the second page:
H2=10
M2=30
S2=30
when the program subtract S2 with S it equals to 20 seconds. So the user has spent 20 sec in typing all the fields.
But the problem is:
H=10
M=30
S=30
and
H2=10
M2=30
S2=30

S2-S=0

so the Label1.text it equals to "30-30=0"..

I hope you understand my problem. Please help me.

thanx

If you disregard the time it takes to lift you hand from the keyboard in order to move the mouse the button.

You could do this more simpler by using javascript to time the keyboard interaction from the time the first character has been typed until a button has been clicked.
That would give you the exact time in seconds without having to calculate it using TimeSpan.

You can store the time ticks in a asp.net hidden field from the javascript code, and then read that value on postback.

A simple javascript stopwatch can be found here: http://www.codeproject.com/Articles/29330/JavaScript-Stopwatch

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.