Home All Groups Group Topic Archive Search About

Real Runtime Control -?-

Author
10 May 2007 3:38 PM
Harvey Triana
Hello...

Private WithEvents MyTimer As VB.Timer

Private Sub cmdCreateTimer_Click()
    Set MyTimer = Me.Controls.Add("VB.Timer", "tmrMyTimer", Me)
    MyTimer.Interval = 500
    MyTimer.Enabled = True
End Sub

Private Sub cmdRemoveTimer_Click()
    MyTimer.Enabled = False
    Set MyTimer = Nothing
    Me.Controls.Remove "tmrMyTimer"
End Sub

Private Sub MyTimer_Timer()
    ' do something ...
End Sub

-- Works! The porpuse is to create eventually a Timer in runtime.
-- What do thing about this code?

<Harvey Triana />

Author
10 May 2007 4:05 PM
Karl E. Peterson
Hi Harvey --

> Private WithEvents MyTimer As VB.Timer
<snip>
> -- Works! The porpuse is to create eventually a Timer in runtime.
> -- What do thing about this code?

Well, what's the purpose?  You haven't saved the need for a form.  It's still not an
option in VB5 or VBA.

If you want to create timers at runtime, I offer an class-based approach on my
site -- http://vb.mvps.org/samples/TimerObj

Later...   Karl
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
10 May 2007 4:17 PM
Harvey Triana
Hi Karl.

> Well, what's the purpose?
OK. I have to implement an option of blinking in an user control that will
be used very few times. The client uses an array of approximately 100
instances of the control. Well, thus i use less resources - doesn't it?

<Harvey Triana />

Show quoteHide quote
"Karl E. Peterson" <k***@mvps.org> escribió en el mensaje
news:eBF2I0xkHHA.4848@TK2MSFTNGP05.phx.gbl...
> Hi Harvey --
>
>> Private WithEvents MyTimer As VB.Timer
> <snip>
>> -- Works! The porpuse is to create eventually a Timer in runtime.
>> -- What do thing about this code?
>
> Well, what's the purpose?  You haven't saved the need for a form.  It's
> still not an option in VB5 or VBA.
>
> If you want to create timers at runtime, I offer an class-based approach
> on my site -- http://vb.mvps.org/samples/TimerObj
>
> Later...   Karl
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>
Author
10 May 2007 4:39 PM
Karl E. Peterson
Harvey Triana <harveytri***@hotmail.com> wrote:
>> Well, what's the purpose?
>
> OK. I have to implement an option of blinking in an user control that will
> be used very few times. The client uses an array of approximately 100
> instances of the control. Well, thus i use less resources - doesn't it?

I wouldn't think so.  To make the extreme case, it's quite possible to share a
single code-based timer in a situation as you suggest
(http://vb.mvps.org/samples/SyncEvts).  But to create 100 window-based timers is
sucking up far more resources.  The only concievable (by me) reason for doing that
might be to allow for a randomness in the event firings, rather than the more
ordered firings offered by a shared timer.  Then again, you can still save the
overhead of additional windows and messages by using individual code-based timer
callbacks.
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
10 May 2007 4:54 PM
Harvey Triana
Excellent.  Thanks Karl.

<Harvey Triana />

Show quoteHide quote
"Karl E. Peterson" <k***@mvps.org> escribió en el mensaje
news:%23VUd7GykHHA.3512@TK2MSFTNGP06.phx.gbl...
> Harvey Triana <harveytri***@hotmail.com> wrote:
>>> Well, what's the purpose?
>>
>> OK. I have to implement an option of blinking in an user control that
>> will
>> be used very few times. The client uses an array of approximately 100
>> instances of the control. Well, thus i use less resources - doesn't it?
>
> I wouldn't think so.  To make the extreme case, it's quite possible to
> share a single code-based timer in a situation as you suggest
> (http://vb.mvps.org/samples/SyncEvts).  But to create 100 window-based
> timers is sucking up far more resources.  The only concievable (by me)
> reason for doing that might be to allow for a randomness in the event
> firings, rather than the more ordered firings offered by a shared timer.
> Then again, you can still save the overhead of additional windows and
> messages by using individual code-based timer callbacks.
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>