Using CallByName with nested objects

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!

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing