Alessandro Mandelli
Alessandro Mandelli

Reputation: 581

How to get the property value of a class based on property number

I tried to search for an already posted answer, but was unable to find any, although some threads provided some hints.

What I normally do to set the same property across numbered instances of controls is something like:

  DirectCast(Me.Controls.Item("Picturebox" & port), PictureBox).Tag = "some tag"

Is there a similar approach if I want to loop around numbered properties class1.property1 to class1.property99 of a class?

Upvotes: 3

Views: 56

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27322

CallByName is what you are looking for. I think it uses reflection under the bonnet (hood) so might not be that efficient:

For i As Integer = 1 to 99    
    CallByName(class1, "property" & i.ToString(), CallType.Set, "New Value")
Next

Upvotes: 3

Related Questions