|
|
|
As explained in the Mistake Bank you need all three flavors of Property procedures to correctly implement a Variant property that can take either an object or a non-object value. Surprisingly enough, in this case you don't need that the argument of the Property Set procedure be declared As Variant. In fact, you can slightly optimize your code by declaring the argument of the Property Set procedure using As Object instead: |
You can build on this undocumented capability to write more concise code and further optimize the procedure by using a more specific type of object. For example, let's assume that the Address property can take either a string or a CAddress object. You might believe that you need to test the type of the object at run-time using this code: |
Click here to copy the following block | Dim m_Address As Variant
Property Set Address(newValue As Variant) If TypeName(newValue) <> "CAddress" Then Err.Raise 1003, , "A CAddress object is expected" End If Set m_Address = newValue End Property |
However, you can let Visual Basic do the test on your behalf, and build a better routine as follows: |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|