Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Better type checking in Variant properties that can accept objects

Total Hit ( 2916)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


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:

Click here to copy the following block
Property Set Tag(newValue As Object)
  Set m_Tag = newValue
End Property

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:

Click here to copy the following block
Dim m_Address As Variant

Property Set Address(newValue As CAddress)
  Set m_Address = newValue
End Property


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 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.