Consulting

Results 1 to 6 of 6

Thread: Watch Window Displays Properties and Private Variables

  1. #1

    Watch Window Displays Properties and Private Variables

    Hello,

    I have a question an I would love to have it solved. (if possible). Why is it that the watch windows show all the variables of a class and also my properties? Is there a way to avoid this?

    It's very confusing I think


    Private m_strName As String
    Private m_strLastName As String
    Private m_strSex As String
    Private m_blnIsMaried As Boolean
    Private m_dblIncome As Double
    
    Public Property Get Name() As String
        Name = m_strName
    End Property
    Public Property Let Name(ByVal strName As String)
        m_strName = strName
    End Property
    
    Public Property Get LastName() As String
        LastName = m_strLastName
    End Property
    Public Property Let LastName(ByVal strLastName As String)
        m_strLastName = strLastName
    End Property
    
    Public Property Get Sex() As String
        Sex = m_strSex
    End Property
    Public Property Let Sex(ByVal strSex As String)
        m_strSex = strSex
    End Property
    
    Public Property Get IsMaried() As Boolean
        IsMaried = m_blnIsMaried
    End Property
    Public Property Let IsMaried(ByVal blnIsMaried As Boolean)
        m_blnIsMaried = blnIsMaried
    End Property
    
    Public Property Get Income() As Double
        Income = m_dblIncome
    End Property
    Public Property Let Income(ByVal dblIncome As Double)
        m_dblIncome = dblIncome
    End Property

    Capture.jpg


    Thanks a lot for the help
    Feedback is the best way for me to learn


    Follow the Armies

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Don't know if you're interested in this any more

    Instead of 'Watching' an instance of the class, just Watch the property or variable
    Attached Images Attached Images
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    I agree Fred, it is a real pain. No way to avoid it as far as I can see.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    BTW, never use Sex in your code, use Gender, corporate filters might misconstrue
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    @Paul;

    Thanks for the reply; and I am always interested in knowledge

    Yes, I can use that, but sometimes I have a small class and I want to visually check that all the properties have a value; or the correct value and I can easily do this with class instance watch. This is just me being extra picky; just asking in this forums perhaps people with more experience in the field knew of a way to do it. In other IDE you don't see the class variables.

    untitled.jpg


    I wish we could have a more advanced IDE for VBA lol


    @xld;
    I know. And yeah that was a poor choice on my end. I was creating this small sample to explain my problem and in my mind I was thinking on one of those forms you fill out at the doctor's office lol

    Thanks for the help.
    Feedback is the best way for me to learn


    Follow the Armies

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    what I like to do is to include a 'Dump' method in my class that I use to display variables during development

    The method can be as elaborate or as raw as I think might be needed

    I usually use the class Initialization to set Null values


    Option Explicit
    Sub drv()
        Dim Tom As New clsPerson
        Dim Mary As New clsPerson
        
        With Tom
            .Gender = "Male"
            .Income = 100000
            .IsMarried = True
            .LastName = "Smith"
            .Name = "Thomas"
        End With
        
        Call Mary.Add("Mary", "Jones")
        
        Call Tom.Dump
        Call Mary.Dump
    End Sub

    Option Explicit
    Private m_strName As String
    Private m_strLastName As String
    Private m_strGender As String
    Private m_blnIsMarried As Boolean
    Private m_dblIncome As Double
    
    
    Private Sub Class_Initialize()
        Name = "-"
        LastName = "-"
        Gender = "-"
        IsMarried = False
        Income = -1
    End Sub
    
    Sub Add(FN As String, LN As String)
        Name = FN
        LastName = LN
    End Sub
    
    Sub Dump()
        Dim s As String
      
        s = "Name         : " & Name & vbCrLf
        s = s & "Last Name    : " & LastName & vbCrLf
        s = s & "Gender       : " & Gender & vbCrLf
        s = s & "Married      : " & IsMarried & vbCrLf
        s = s & "Income       : " & Format(Income, "$#,##0")
        
        Call MsgBox(s, vbInformation + vbOKOnly, "Dump 'clsPerson'")
        
    End Sub
     
     
    Property Get Name() As String
        Name = m_strName
    End Property
    Property Let Name(ByVal strName As String)
        m_strName = strName
    End Property
    Property Get LastName() As String
        LastName = m_strLastName
    End Property
    Property Let LastName(ByVal strLastName As String)
        m_strLastName = strLastName
    End Property
    Property Get Gender() As String
        Gender = m_strGender
    End Property
    Property Let Gender(ByVal strGender As String)
        m_strGender = strGender
    End Property
    Property Get IsMarried() As Boolean
        IsMarried = m_blnIsMarried
    End Property
    Property Let IsMarried(ByVal blnIsMarried As Boolean)
        m_blnIsMarried = blnIsMarried
    End Property
    Property Get Income() As Double
        Income = m_dblIncome
    End Property
    Property Let Income(ByVal dblIncome As Double)
        m_dblIncome = dblIncome
    End Property
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •