Change label when variable changes

This is probably a very simple question, but its something I never got around to learning.  How would I make it so that when a certain global variable changes, so does a label on a form without making a timer.  I had this for my timer:

Private Sub Timer1_Timer()

Label1.Caption = TheVar

end sub

But I remember seeing somewhere that timers shouldn't be used unless completely necessary because of the resources they CAN take up and I was calling this timer every second.  If I'm wrong, and I can leave the timer the way it is because it does so little, then let me know.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

polaughlinAuthor Commented:
Edited text of question.
Dr. Kamal MehdiCommented:
The solution depends on how you change your global variable.
For example, if the variable is an input from the user (in a text box), then simply you can use the Text1_Changed event to synchronize the label's caption. If you change your variable within your code, then you can simply add a single line of code to change the label caption.
Hope that helps.
You can add public properties instead of the public variable. For example like this..

Private m_PubVar As Long

Public Property Let PubVar(New_Value As Long)

  m_PubVar = New_Value
  Form1.Label1.Caption = m_PubVar    <-- the value has changed update the label caption, or whatever
End Property

Public Property Get PubVar() As Long

  PubVar = m_PubVar  
End Property

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

polaughlinAuthor Commented:
The problem is, kamall, the variable is changed often in many different places and I'm looking for an easier way to do it rather than going through and finding all of the places that it is changed and adding another line of code.  Thanks anyway.  I appreciate it. :-)
polaughlinAuthor Commented:
This is exactly what I was looking for.  Thanks.
polaughlinAuthor Commented:
Actually, after thinking about this and trying to work this into my program, I found out its not going to work the way I want it.  The variable is not only set in my program, its also referred to in various functions.  Example:

Not just this:

TheVar = "This this and this"

but also:

MsgBox TheVar, vbCritical


VB returns the following error: Invalid use of property.

Is there some other way to do this and still be able to use the variable in a function, is there a workaround, or am I just doing something completely wrong? :P
Have you added the "Public Property Get" procedure? The MsgBox works just fine for me, but when I remove the "Public Property Get" procedure I get the 'Invalid use of property' error. Make sure you add both Public Property Let and Public Property Get.
polaughlinAuthor Commented:
Ok, now I feel like a moron.  That worked.  Thanks alot.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.