I have created a simple application where I fetch questions from an Access database and store the answers to another Access database. I am not sure how many questions client would like to ask, so I can’t hardcode that number.
So, column names for answers table (besides user information like first, last name and so on) will be a1, a2, a3 … aN.
And finally the problem!
For testing purposes I have hardcoded saving first 3 answers like this:
newEntry.a1 = answers(0)
newEntry.a2 = answers(1)
newEntry.a3 = answers(2)
Now I would like to iterate through all properties based on count of “a-type” properties:
'aCount is number of "a-type" properties
For i = 0 To aCount - 1
Dim property As String
property = "a" & (i + 1)
newEntry.property = answers(i)
Next
Of course, above code does not work, it is just a pseudo-code idea that “should” to the same as my hardcoded example.
Is it possible to iterate through predefined properties of newEntry object in that manner?
I hope my question was clear enough. Thank you very much in advance!
Yes there is using reflection, you’d be better off using a collection to store your answers.
lots of ways you could do it, but
PSEUDO Code
so A4 is simply newEntries[“A”][3];