J
Joseph Gruber
Hi all. I'm looking for some help here. My app creates a runtime
label which is used as a clock -- it also then creates the timer for
this clock at runtime. When the timer tick's clockUpdate is called
(through AddHandler) and I use Controls.Find to find the runtime
label. This works somewhat except that it seem for every 3 out of 4
ticks the following error is thrown: A first chance exception of type
'System.IndexOutOfRangeException' occurred in mscorlib.dll
Any ideas why? Sample code is below. Both of these subs, and the
code that builds the runtime controls are in a seperate module from
the forms.
Thanks
Sub buildTimer(ByVal timer As System.Windows.Forms.Timer)
timer.Enabled = True
timer.Interval = 500
AddHandler timer.Tick, AddressOf clockUpdate
End Sub
Sub clockUpdate(ByVal sender As Object, ByVal e As System.EventArgs)
Dim valLocalTime As System.Windows.Forms.Label = Nothing
Dim frm As System.Windows.Forms.Form =
System.Windows.Forms.Form.ActiveForm
Try
valLocalTime = frm.Controls.Find("valLocalTime", True)(0)
Catch ex As Exception
End Try
If Not valLocalTime Is Nothing Then valLocalTime.Text =
My.Computer.Clock.LocalTime.ToString("HH:mm:ss") & " EDT"
valLocalTime = Nothing
frm = Nothing
End Sub
label which is used as a clock -- it also then creates the timer for
this clock at runtime. When the timer tick's clockUpdate is called
(through AddHandler) and I use Controls.Find to find the runtime
label. This works somewhat except that it seem for every 3 out of 4
ticks the following error is thrown: A first chance exception of type
'System.IndexOutOfRangeException' occurred in mscorlib.dll
Any ideas why? Sample code is below. Both of these subs, and the
code that builds the runtime controls are in a seperate module from
the forms.
Thanks
Sub buildTimer(ByVal timer As System.Windows.Forms.Timer)
timer.Enabled = True
timer.Interval = 500
AddHandler timer.Tick, AddressOf clockUpdate
End Sub
Sub clockUpdate(ByVal sender As Object, ByVal e As System.EventArgs)
Dim valLocalTime As System.Windows.Forms.Label = Nothing
Dim frm As System.Windows.Forms.Form =
System.Windows.Forms.Form.ActiveForm
Try
valLocalTime = frm.Controls.Find("valLocalTime", True)(0)
Catch ex As Exception
End Try
If Not valLocalTime Is Nothing Then valLocalTime.Text =
My.Computer.Clock.LocalTime.ToString("HH:mm:ss") & " EDT"
valLocalTime = Nothing
frm = Nothing
End Sub