Click to See Complete Forum and Search --> : Adding controls to a class
bstripp
Apr 25th, 2001, 11:47 AM
I am trying to insert a timer object into a class that I created and having all sorts of problems doing it. Here is what I was trying:
Private withevents timer1 as timer
Then in one of the subs, I wanted to do the following
set timer1 = new timer
However, when I try it, it does not recognize the timer as a valid control. How do I add the timer as a valid control to my class?
Bill Stripp
bstripp@gr.com
ELampman
Apr 27th, 2001, 10:13 PM
The easiest way to do this is to add a form to your project and add the timer control to the form.
Then when you create the object, include the following code to instantiate the timer:
Private frmTimer as new frmTimer
Private withevents tmrAlarm as timer
As long as you don't 'show' the form, it will be invisible.
In your terminate code for the object, set the timer control and th form = Nothing
bstripp
Apr 30th, 2001, 07:52 AM
Thanks for the reply.
However, doesn't that mean that my class is no longer as portable. I was hoping for a class that I could add into any project without myself, or other folks having to do anything to make it work. I have been able to do this with controls that referenced, but not included in the scope of the project. Since the timer is always an included component, I have not been able to figure out how to add it otherwise.
Bill Stripp
Ed Lampman
Apr 30th, 2001, 02:20 PM
Referencing a form in your class module doesn't make your class any less portable, it just means that you're loading more code into memory to support the form. The form then supports the control.
There is another way to use a system timer but I'm not familiar with it. You could search Msn.com for 'system timer'.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.