Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
What of these is the correct syntax to refer to Properties?
Hi all
Just a simple question really: I was wondering if there was an accepted syntax for refering to already defined properties when writing a sub/function in the same class. For example: <Declarations Private lBaseNum as Long </Declarations <Class1 Code Public Property Get BaseNumber() As Long BaseNumber = lBaseNum End Property Public Property Let BaseNumber(ByVal vNewValue As Long) lBaseNum = vNewValue End Property Public Function AdjBaseNumber(Adj as Long) AdjBaseNumber = BaseNumber + Adj End Function </Class1 Code The question arises in the Function AdjBaseNumber, which of the following is correct: a) AdjBaseNumber = BaseNumber + Adj b) AdjBaseNumber = lBaseNum + Adj In a) I reference the Property (BaseNumber) but in b) I reference the Private variable (lBaseNum) Does it make any difference? Thanks a lot Lloyd |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
What of these is the correct syntax to refer to Properties?
I always referee to the internal, private value within the code because if
you refer to the property name, you could inadvertently call the code associated with it. Consider this example Option Explicit Private mTest As Long Public Property Let TestValue(val As Long) mtest1 = val mtest1 = mtest1 * 2 End Property Public Property Get TestValue() As Long TestValue = mtest End Property Function Test() TestValue = mtest End Function then run this code against the class Set cTest = New Class1 cTest.TestValue = 7 MsgBox cTest.TestValue cTest.Test MsgBox cTest.TestValue You will see that TestValue has been changed internally when (possibly) not expected. -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "pinkfloydfan" wrote in message ups.com... Hi all Just a simple question really: I was wondering if there was an accepted syntax for refering to already defined properties when writing a sub/function in the same class. For example: <Declarations Private lBaseNum as Long </Declarations <Class1 Code Public Property Get BaseNumber() As Long BaseNumber = lBaseNum End Property Public Property Let BaseNumber(ByVal vNewValue As Long) lBaseNum = vNewValue End Property Public Function AdjBaseNumber(Adj as Long) AdjBaseNumber = BaseNumber + Adj End Function </Class1 Code The question arises in the Function AdjBaseNumber, which of the following is correct: a) AdjBaseNumber = BaseNumber + Adj b) AdjBaseNumber = lBaseNum + Adj In a) I reference the Property (BaseNumber) but in b) I reference the Private variable (lBaseNum) Does it make any difference? Thanks a lot Lloyd |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
What of these is the correct syntax to refer to Properties?
Thanks Bob, that's very clearly explained as usual.
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Correct Syntax | Excel Discussion (Misc queries) | |||
CORRECT SYNTAX FOR RUN... | Excel Programming | |||
CORRECT SYNTAX FOR RUN... | Excel Programming | |||
syntax to refer to a range as an array? | Excel Worksheet Functions | |||
If...and... - can never get the syntax correct! | Excel Programming |