| re: dynamic timer reference problem
You need something to hold your timer in. So this works. You probably want
to have "t" become an arraylist if it is going to be a dynamic amount of
timer objects you want to hold. Hope it helps.
Chirs
Public Class Form1
Inherits System.Windows.Forms.Form
dim t As System.Timers.Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
t = New System.Timers.Timer 'TIMER DECLARED HERE
add elapsed time handler
'create start buttons
'add button click handlers
'add range button controls
End Sub
Public Sub btnStart(ByVal sender As Object, ByVal e As System.EventArgs)
t.Enabled = True
End Sub
"Kris Palmer" <kristeenpalmer@REMOVEyahoo.com> wrote in message
news:Xns95ECA51A4F4F8kristeenpalmeratyaho@130.81.6 4.196...[color=blue]
> hi,
> can somebody explain this problem? it's driving me crazy!
> i have a requirement to dynamically create a variable quantity of timers
> with associated start button based on the contents of a database. if i
> create system timers dynamically, i cannot reference them from the start
> button click event handler. the build error is ' <timer name> not
> declared>
> ----
> however, if i declare the system timers outside runtime code, everything
> works fine! ....but that doesn't do me much good since i dont' know how
> many timers i'll need at design time.
> gotta be syntax or something. thanks in advance. kris
>
>
> ---- THIS WORKS -----
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
> Private t As New System.Timers.Timer 'TIMER DECLARED HERE
>
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'create start buttons
> 'add button click handlers
> 'add range button controls
> End Sub
>
>
> Public Sub btnStart(ByVal sender As Object, ByVal e As System.EventArgs)
> t.Enabled = True
> End Sub
>
>
>
>
> ---- DOES NOT BUILD ----
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
> 'timer declaration added
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> dim t As New System.Timers.Timer 'TIMER DECLARED HERE
> add elapsed time handler
>
> 'create start buttons
> 'add button click handlers
> 'add range button controls
> End Sub
>
>
> Public Sub btnStart(ByVal sender As Object, ByVal e As System.EventArgs)
> t.Enabled = True !!!!!!! CAUSES BUILD ERROR (t not declared)
> End Sub
>
>
>
>[/color] |