locked
How to monitor a class property when the class object is used in another code module? RRS feed

  • Question

  • Hello I am looking to see if there is a way to monitor and execute code when a variable/property in a class object has changed value during run time.

    Here is one way I tried to pull it off....

    Create this class:

    Option Compare Database
    Option Explicit
    Private p_bVarToMonitor As Boolean
    Public Property Get bVarToMonitor() As Boolean
        bVarToMonitor = p_bVarToMonitor
    End Property
    Public Property Let bVarToMonitor(v As Boolean)
    
        p_bVarToMonitor = v
        If v = False Then
            GoTo bVarToMonitorFalse
        End If
    
    End Property


    Then test it in a module (not in the class module):

    Sub test()
    
    Dim m As clsVarMonitorBoolean
    Set m = New clsVarMonitorBoolean
    
    m.bVarToMonitor = False 'this should make it goto bVarToMonitorFalse:
    
    'Code to skip when bVarToMonitor = False
    
    Exit Sub
    bVarToMonitorFalse:
    
    'other alternative code to run when bVarToMonitor = False
    
    End Sub

    ...however, it doesn't work because the goto label is in a different module. Note, I need to use the class object in a regular code module, not within the same class module.

    Is there an variable_change event that I can setup or something?

    Thursday, July 2, 2015 3:05 PM

All replies

  • Try...

    Option Compare Database
    Option Explicit
    
    Private p_bVarToMonitor As Boolean
    
    Public Property Get bVarToMonitor() As Boolean
        bVarToMonitor = p_bVarToMonitor
    End Property
    
    Public Property Let bVarToMonitor(v As Boolean)
        p_bVarToMonitor = v
    End Property

    Sub test()
    
        Dim m As clsVarMonitorBoolean
        
        Set m = New clsVarMonitorBoolean
        
        m.bVarToMonitor = False 'this should make it goto bVarToMonitorFalse:
        
        If m.bVarToMonitor = False Then GoTo bVarToMonitorFalse
        
        'Code to skip when bVarToMonitor = False
        
        Exit Sub
        
    bVarToMonitorFalse:
    
    'other alternative code to run when bVarToMonitor = False
    
    End Sub

    Hope this helps!


    Domenic Tamburino Microsoft MVP - Excel xl-central.com - "For Your Microsoft Excel Solutions"

    Thursday, July 2, 2015 3:31 PM