Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB6
Expertise: Intermediate
Apr 29, 2000

Using CallByName with nested objects

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


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:

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:


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!
Leigh Bateman
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date