Dynamically add timer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anuragshrivastava64
    New Member
    • Jan 2007
    • 66

    Dynamically add timer

    Is there any way to add a timer control while run time

    similar to textbox
    Set txtNew = Controls.Add("V B.TextBox", "TextDynami c")
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by anuragshrivasta va64
    Is there any way to add a timer control ...
    You might be able to work without it. If you need to do multiple timers, why not just use a single control and fire different events based on your own counters? For example...

    [CODE=vb]Private Sub Timer1_Timer()
    Static Counter1 As Long
    Static Counter2 As Long
    Counter1 = Counter1 + 1
    Counter2 = Counter2 + 1
    If Counter1 >= Limit1 Then
    ' Call your first timed routine
    Counter1 = 0
    End If
    If Counter2 >= Limit2 Then
    ' Call your second timed routine
    Counter2 = 0
    End If
    End Sub
    [/CODE]Of course, it would be better to base the events on actual elapsed time since the last firing, rather than a simple count, in case you need to change the Interval of the timer control.

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      Place a Timer On the Form in Design Time, and Make Index = 0
      To Add One More Timer, just use this code:

      Load Timer1(1)

      With above code, you can use Events associated with cotrols loaded during Run-Time...
      But if you add Controls, You have to Create Events, Which is a Very Tedious process..


      Regards
      Veena

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Yes, if you're using VB6, then a control array is certain to be the simplest way to implement this.

        Comment

        Working...