Reputation: 392
I'm trying to change some logic in VB6 code, and I need to get control property by property name. Something similar to Access control.properties property.
Dim propertyName as string
propertyName ="Visible"
Me.Controls("mnuRepots").Properties(propertyName)="True"
But my VB6 says Object doesn't support this property or method
Upvotes: 1
Views: 604
Reputation:
To execute a method or set or get a property based on a dynamic name, you can use the CallByName
function, like this:
CallByName mnuReports, "Visible", vbLet, True
Note that there's almost always a better approach to calling different code in different cases by using polymorphism or a simpler Select Case statement. Loading code dynamically can make code much harder to read, and (if you're ever taking any input from an untrusted source) an easy place to screw up and allow people to call methods that aren't the ones you intended them to call, leading to security vulnerabilities.
Upvotes: 5