PDA

View Full Version : Watch Window Displays Properties and Private Variables



fredlo2010
07-18-2014, 09:23 AM
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




11984


Thanks a lot for the help :)

Paul_Hossler
02-19-2015, 08:13 AM
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

Bob Phillips
02-19-2015, 09:35 AM
I agree Fred, it is a real pain. No way to avoid it as far as I can see.

Bob Phillips
02-19-2015, 09:37 AM
BTW, never use Sex in your code, use Gender, corporate filters might misconstrue :)

fredlo2010
02-20-2015, 07:01 AM
@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.

12887


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.

Paul_Hossler
02-21-2015, 09:01 AM
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