So, I have an object with some properties, like this:
Dim.d1="Description A", Dim.d2="Description B",etc
for i=0 until 49
e.Row.Cells[i].Text = Evaluate(Dim.d(i+1))
You can use methods in the
System.Reflection namespace to do this. However, the answer is presented in order to answer the question - you should look at using some of the options suggested by other answerers e.g. use a
List(Of String) or something similar.
Anyway, let's say you have a class:
Public Class Class1 Public Property d1 As String Public Property d2 As String Public Property d3 As String End Class
And then, let's say you create an instance of that class and set its properties:
Dim obj As New Class1 obj.d1 = "Foo" obj.d2 = "Bar" obj.d3 = "Test"
If you then want to have a loop from 1 to 3, and access e.g.
d2 etc then this is where you use
For i As Integer = 1 To 3 Dim info As System.Reflection.PropertyInfo = obj.GetType().GetProperty("d" & i) Dim val As String = info.GetValue(obj, Reflection.BindingFlags.GetProperty, Nothing, Nothing, Nothing) Debug.Print(val.ToString) Next
Will give you the output:
Foo Bar Test