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

Using CallByName with nested objects

Total Hit ( 3118)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Sometimes Microsoft documentation can be, well lacking is a kind word, and one is reluctant to call tech support when they smoke your credit card first, and ask questions later.

My problem was that the CallByName procedure was refusing to call nested lasses. To see what I mean, consider that if your class exposes an X public variable, you can set it to zero from within the class itself using this code

Click here to copy the following block
CallByName me, "X", vbLet, 0

But, what happens if you have an array of objects, say Data(), and you want to set the X property for any object in the array, given its index? The first attempt I made was:

Click here to copy the following block
CallByName Me, "Data(index).X", vbLet, 0

which tesults in the error "Object doesn't support this property or method".
Hmmmm, seems like the 'C' VB programmers were not willing to go the extra mile for us. I was desperate to use this function so I persisted until I found the following hack:

Click here to copy the following block
CallByName CallByName(Me, "Data", vbGet, index), "X", vbLet, 0

The second CallByname creates an object reference (pointer) direct to the nested class object, thus we are not using any nested calls in the function. I see no reason why you couldn't keep nesting this hack if you have further nested class objects. Just remember VB is using late binding in all these calls!


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.