[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

BeeJ

9/15/2011 10:44:00 PM

What are the pros and cons of using this code vs ploping a Timer on to
a form? I guess this question can be generalized to all types of
controls. Maybe more concerned about start up and shut down perils.

Private WithEvents TTimer As VB.Timer '

Private Sub TimerInit()

Set TTimer = Controls.Add("VB.Timer", "TTimer")
TTimer.Interval = 100 ' mSec interval
TTimer.Enabled = True ' start TTimer

End Sub '


4 Answers

Dee Earley

9/16/2011 11:44:00 AM

0

On 15/09/2011 23:44, BeeJ wrote:
> What are the pros and cons of using this code vs ploping a Timer on to a
> form? I guess this question can be generalized to all types of controls.
> Maybe more concerned about start up and shut down perils.
>
> Private WithEvents TTimer As VB.Timer '
>
> Private Sub TimerInit()
>
> Set TTimer = Controls.Add("VB.Timer", "TTimer")
> TTimer.Interval = 100 ' mSec interval
> TTimer.Enabled = True ' start TTimer
>
> End Sub '

No difference but no real gain either.
It still needs to be called/run from a form module and needs that form
to be loaded for the events to fire.

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Schmidt

9/16/2011 11:58:00 AM

0

Am 16.09.2011 00:44, schrieb BeeJ:
> What are the pros and cons of using this code vs ploping a Timer on to a
> form? I guess this question can be generalized to all types of controls.
> Maybe more concerned about start up and shut down perils.
>
> Private WithEvents TTimer As VB.Timer '
>
> Private Sub TimerInit()
>
> Set TTimer = Controls.Add("VB.Timer", "TTimer")
> TTimer.Interval = 100 ' mSec interval
> TTimer.Enabled = True ' start TTimer

The Pros are, that you can remove such
dynamically added controls, whilst the
Form is (or remains) running.
The Timer is not the best example maybe
for such dynamic removing (it really does
not eat that much resources, whilst on a
Form) - but this can come in handy, when
you want a Form with e.g. 20+ "TabViews"
or something like that - instead of hiding
unused views (which still remain loaded then)
you could alternatively load the currently
requested tab only.

As for the removing:
To get e.g. rid of the timer when used as in
the example above, you would need to relase
it in *two* places (where the instance is
referenced from):

1: your TTimer-WithEvents-Variable
Set TTimer = Nothing

2: and you need to remove it also from the Form-
or UserControls Controls-Collection (the
thing, where you added it to).
Controls.Remove "TTimer" 'same Key as in the Add

Olaf

Karl E. Peterson

9/16/2011 6:55:00 PM

0

Schmidt pretended :
> The Pros are, that you can remove such
> dynamically added controls, whilst the
> Form is (or remains) running.

Way back in the VB2, or maybe it was VB3, days, I knew a guy who liked
to say that you could produce *any* form necessary by simply sticking a
single invisible instance of all the intrinsic controls on it. Each,
of course, element (0) of its own control array. <g>

--
..NET: It's About Trust!
http://vfre...


Tony Toews

9/16/2011 9:15:00 PM

0

On Fri, 16 Sep 2011 11:55:01 -0700, Karl E. Peterson <karl@exmvps.org>
wrote:

>Way back in the VB2, or maybe it was VB3, days, I knew a guy who liked
>to say that you could produce *any* form necessary by simply sticking a
>single invisible instance of all the intrinsic controls on it. Each,
>of course, element (0) of its own control array. <g>

A guy I know had the video game Frogger working in an Access form in a
similar fashion.

(Yes, yes I know, he should've written it in VB6. <smile>)

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
Tony's Microsoft Access Blog - http://msmvps.com/blo...
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeup...