Home > Archive > Visual Basic > April 2006 > Sharing variables and code in an OCX between two ctl's and a .bas
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Sharing variables and code in an OCX between two ctl's and a .bas
|
|
| Richard Lewis Haggard 2006-04-30, 6:56 pm |
| I have an OCX which has two CTL's in it. I'd like to create some code that
both of the CTL's can make use of. The shared code and the two CTL's all
need to share some global variables. The problem is, I'm having a bit of
trouble coming up with the appropriate syntax that permits this. What is the
syntax that allows a Boolean, for example, to be declared in the shared .BAS
file to be used in both of the .CTL files?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com
| |
| Richard Lewis Haggard 2006-04-30, 6:56 pm |
| Never mind. Figured it out.
Public bConnected As Boolean
--
Richard Lewis Haggard
www.Haggard-And-Associates.com
"Richard Lewis Haggard" <HaggardAtWorldDotStdDotCom> wrote in message
news:e4vYEbIbGHA.3812@TK2MSFTNGP04.phx.gbl...
>I have an OCX which has two CTL's in it. I'd like to create some code that
>both of the CTL's can make use of. The shared code and the two CTL's all
>need to share some global variables. The problem is, I'm having a bit of
>trouble coming up with the appropriate syntax that permits this. What is
>the syntax that allows a Boolean, for example, to be declared in the shared
>.BAS file to be used in both of the .CTL files?
> --
> Richard Lewis Haggard
> www.Haggard-And-Associates.com
>
| |
|
| Keep in mind this *probably* isn't a good idea. When you start sharing data
between controls (or classes, in general), you can get into trouble real
quick. For example, one of the controls changes the value of the variable
and this has a negative impact on the other control. Basically, what you're
doing is breaking a key concept of COM called encapsulation. It's rare that
this is ever a good thing to do.
If I were you, I'd rethink my design. You most certainly should be able to
accomplish what you need without breaking encapsulation.
--
Mike
Microsoft MVP Visual Basic
"Richard Lewis Haggard" <HaggardAtWorldDotStdDotCom> wrote in message
news:uapkXdIbGHA.996@TK2MSFTNGP04.phx.gbl...
> Never mind. Figured it out.
>
> Public bConnected As Boolean
> --
> Richard Lewis Haggard
> www.Haggard-And-Associates.com
>
> "Richard Lewis Haggard" <HaggardAtWorldDotStdDotCom> wrote in message
> news:e4vYEbIbGHA.3812@TK2MSFTNGP04.phx.gbl...
>
>
|
|
|
|
|