|
-
Aug 3rd, 2004, 12:13 PM
#1
Thread Starter
New Member
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
-
Aug 3rd, 2004, 03:15 PM
#2
I just cut and pasted your code and everything worked fine, in what way isn't it working?
-
Aug 3rd, 2004, 03:25 PM
#3
Thread Starter
New Member
hmm well apparently, the code runs, but for some reason nothing happens on the page... do you have a possible explanation for that?
-
Aug 3rd, 2004, 03:27 PM
#4
I wonder how many charact
Ultima....
Are you using a browser other than IE6 for testing?
-
Aug 3rd, 2004, 04:39 PM
#5
Thread Starter
New Member
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
-
Aug 3rd, 2004, 06:07 PM
#6
VB Code:
lbl4.Text = "you have finished the test"
button2.Visible = False
rb.Visible = False
Button1.Visible = True
lbl1.Visible = True
lbl2.Visible = True
lbl3.Visible = True
txt1.Visible = True
txt2.Visible = True
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......
-
Aug 3rd, 2004, 06:31 PM
#7
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.
-
Aug 4th, 2004, 09:33 AM
#8
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|