Re: VB6 sharing variables between instances of a control



> 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..
>


.



Relevant Pages

  • A thought for Tk: -mywidgettype option?
    ... I find it'd be handy to know what type of widget ... just using a switch command. ... Just return the widget type on the presence ...
    (comp.lang.tcl)
  • Re: widget question
    ... >> Having just tried Tiger for some week or so, ... >> machine or unload the widget it must be re-entered every time. ... > When I used the weather widget it was fine. ... I have a few widgets that are really handy on my Powerbook. ...
    (comp.sys.mac.apps)
  • Re: disk space calculator
    ... not a widget, though. ... > Nice widget for OSX, online tool is handy for the rest of us ...
    (rec.arts.movies.production.sound)
  • disk space calculator
    ... Nice widget for OSX, online tool is handy for the rest of us ...
    (rec.arts.movies.production.sound)

Loading