Re: VB6 sharing variables between instances of a control
- From: "Joseph Geretz" <jgeretz@xxxxxxxxxx>
- Date: Fri, 23 Sep 2005 00:37:10 -0400
> I should add... this can come in handy once in a while.
Very handy indeed. We have an application which implements a common
navigation widget on every form. Since the navigation context is common
throughout the entire application, changes made via one widget need to
update all other widgets accordingly. We use Global (BAS) variables to
maintain shared state. We also use a system of callbacks (each widget
'registers' itself in a global table of object references). When specific
events occur, all widgets are notified to synch themselves accordingly.
Very hand indeed!
- Joe Geretz -
"Ken Halter" <Ken_Halter@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:uO3pLHLtFHA.2212@xxxxxxxxxxxxxxxxxxxxxxx
> "Ken Halter" <Ken_Halter@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:uwLZRBLtFHA.4076@xxxxxxxxxxxxxxxxxxxxxxx
>> declared Public in a bas module are available throughout the project.
>>
>
> I should add... this can come in handy once in a while. For one thing, it
> allows you to keep track of the number of instances. If you wanted to
> limit the number to exactly 2 (or whatever), you could raise an error in
> the Initialize event, which would prevent it from being instantiated. A
> lot of other uses too. This was the first that popped into my head.
> '============UserControl code
> Option Explicit
>
> Private Sub UserControl_Initialize()
> glNumberOfInstances = glNumberOfInstances + 1
> If glNumberOfInstances > 2 Then
> glNumberOfInstances = glNumberOfInstances - 1
> Err.Raise 429 'use a more appropriate error
> End If
> Debug.Print glNumberOfInstances
> End Sub
>
> Private Sub UserControl_Terminate()
> glNumberOfInstances = glNumberOfInstances - 1
> Debug.Print glNumberOfInstances
> End Sub
>
> Public Property Get NumberOfInstances() As Long
> NumberOfInstances = glNumberOfInstances
> End Property
> '============Module code
> Option Explicit
>
> Public glNumberOfInstances As Long
> '============
>
>
> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
> Please keep all discussions in the groups..
>
.
- References:
- VB6 sharing variables between instances of a control
- From: Chip Camden
- Re: VB6 sharing variables between instances of a control
- From: Ken Halter
- Re: VB6 sharing variables between instances of a control
- From: Ken Halter
- VB6 sharing variables between instances of a control
- Prev by Date: Re: Strange permissions problem
- Next by Date: Re: Strange permissions problem
- Previous by thread: Re: VB6 sharing variables between instances of a control
- Next by thread: Re: VB6 sharing variables between instances of a control
- Index(es):
Relevant Pages
|
Loading