Results 1 to 8 of 8

Thread: Timer problem...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    13

    Unhappy Timer problem...

    i'm trying to create a timer that starts when someone clicks a button to start an online test and then ends once the time expires, heres the code. Can someone tell me whats wrong with it?

    Code:
    Protected Sub start_timer(ByVal source As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Timer1.Enabled = False
            Timer1.AutoReset = False
            AddHandler Timer1.Elapsed, AddressOf Timer1_Elapsed
            Timer1.Interval = 60000
            Timer1.Start()
        End Sub

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    I just cut and pasted your code and everything worked fine, in what way isn't it working?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    13
    hmm well apparently, the code runs, but for some reason nothing happens on the page... do you have a possible explanation for that?

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Ultima....

    Are you using a browser other than IE6 for testing?

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    13
    yah, i'm using IE6, when i ran the test, breakpoints tell me that the timer is running, but it doesn't perform any of the commands once it hits the Timer1_Elapsed sub, heres that code for reference

    Code:
    Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
            Timer1.Stop()
            Dim qchoice = Session.Item("num")
            Dim statnumber As Integer
            Dim myquestions = Session.Item("ack")
            Dim dchoice = qchoice + 1
            Dim blank As Integer = 9 - qchoice
            Dim idnumber = Session.Item("ID")
            Dim myconnection As SqlConnection = New SqlConnection("server=(local);database=test1;trusted_connection=sspi")
            Dim markinc As SqlCommand = New SqlCommand("update quiz2 set numberincorrect = numberincorrect + " & CStr(blank) & " where id= " & idnumber, myconnection)
            Dim markblank As SqlCommand = New SqlCommand("update quiz1 set blank = blank + " & CStr(blank) & " where id= " & dchoice, myconnection)
            myconnection.Open()
            If rb.SelectedValue <> Nothing Then
                For statnumber = 1 To 4
                    If rb.SelectedItem.Text = myquestions(qchoice, statnumber) Then
                        Dim statcommand As SqlCommand = New SqlCommand("update quiz1 set r" & CStr(statnumber) & "= r" & CStr(statnumber) & "+ 1 where id=" & dchoice, myconnection)
                        statcommand.ExecuteNonQuery()
                        'marks the selected question into the stat report
                    End If
                Next
                If acawtd(rb.SelectedItem.Text) = True Then
                    Dim mycommand As SqlCommand = New SqlCommand("update quiz2 set numbercorrect = numbercorrect +1 where id=" & idnumber, myconnection)
                    mycommand.ExecuteNonQuery()
                    'marks the selected question as right 
                Else
                    Dim mycommand As SqlCommand = New SqlCommand("update quiz2 set numberincorrect = numberincorrect +1 where id=" & idnumber, myconnection)
                    mycommand.ExecuteNonQuery()
                    'marks the selected question as  wrong
                End If
            Else
                Dim mycommand As SqlCommand = New SqlCommand("update quiz2 set numberincorrect = numberincorrect + 1 where id= " & idnumber, myconnection)
                Dim tucommand As SqlCommand = New SqlCommand("update quiz1 set blank = blank + 1 where id= " & dchoice, myconnection)
                'if the thing is left blank, it'll jump to here and just mark it blank
            End If
            markinc.ExecuteNonQuery()
            markblank.ExecuteNonQuery()
            'marks up the remaining questions that arn't answered
            myconnection.Close()
            lbl4.Text = "you have finished the test"
            button2.Visible = False
            rb.Visible = False
            Session.RemoveAll()
            Button1.Visible = True
            lbl1.Visible = True
            lbl2.Visible = True
            lbl3.Visible = True
            txt1.Visible = True
            txt2.Visible = True
            txt3.Visible = True
        End Sub
    Thanks again for helping

  6. #6
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    VB Code:
    1. lbl4.Text = "you have finished the test"
    2.         button2.Visible = False
    3.         rb.Visible = False
    4.         Button1.Visible = True
    5.         lbl1.Visible = True
    6.         lbl2.Visible = True
    7.         lbl3.Visible = True
    8.         txt1.Visible = True
    9.         txt2.Visible = True
    10.         txt3.Visible = True
    I'd expect all the code to run except these lines so i guess now you'll have to figure out a way of making the screen refresh or the control to cause a postback.

    I'd expect it could be done if you made your own custom control using a timer but i've never tried anything like that......

  7. #7
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    just found this article and it all looks easy enough to achieve afterall, I''m going to leave reading it until tomorrow though i've had enough for today.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    13
    oo wow, thanks for the article, i'll take a look at it, THANKS!

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