Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weirdness when Geting property value on a form object 1

Status
Not open for further replies.

whool

Programmer
Jan 31, 2002
31
AU
In this small test app there are two forms. The first from creates an instance of the second form then opens it:

Private Sub Command1_Click()
Dim f as New Form2
f.show

End Sub


The second form (Form2) has the following code:

Private m_Regionid As Integer
______________________
Property Get Regionid()
If m_Regionid = 0 Then
m_Regionid = 999
End If
Regionid = m_Regionid
End Property
________________________
Private Sub Command1_Click()
Dim x as integer
x = Regionid
m_Regionid = Regionid + 1
End Sub


What puzzels me is that when I step through the code the private m_RegionID variable and the RegionID property already contain the value 999 even before the Property has been called from the Sub routine. (This can be seen by hovering the cursor over the said variables).My interest is purely academic but would still like to know.

thanks in advance
Yael
 
Because a property reacts dynamically when the value is checked.
A normal variable will also show its' value when the cursor is placed over it. The value is then natually taken from the current value of the variable - in other words the variable is checked in order to return its' value.
The same with the property. The property is accessed, and in this case, the code with-in the property statement has to also be accessed in order to get the value of the module level variable. Because it is 0 at that point, the code natually sets the variable to 999.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top