Accessing Structure members

Kane Jeeves

Active member
Joined
May 17, 2006
Messages
44
Programming Experience
5-10
Is there a way to access members of a structure without knowing the member name? E.g.: (pseudo code of course)

Structure MyStr
dim Mem1 as string
dim Mem2 as string
...
dim Mem75 as string
End Structure

dim astruct as New MyStr...

'populate astruct from 75 form fields...

'now get all the values
for i = 1 to 75
astruct.Getvalue("Mem" & cstr(i))
next i

INSTEAD OF...
x = astruct.Mem1
y = astruct.Mem2
...
zzz = astruct.Mem75

I don't want to just slam the structure into an array because I might need to do some special processing on individual fields, but I also don't want to hand code getting the values of 75 fields (I have 3 other forms with 50-100 fields).

Any help is appreciated!

- Kane
 
You would do it using reflection but reflection is not something you should use just because you're too lazy to write the proper code. It is much less efficient and has it's own set of issues. If you know what the properties are at design time then you should code them at design time. If your properties are so similarly named then copy and paste will do the bulk of the work for you. If they're not then it may be hard to do with reflection anyway.
 
Back
Top