sjn78 Posted February 5, 2004 Posted February 5, 2004 I have a structure as follows Structure Players Dim Player1 as String Dim Player2 as String ....... and so on End Structure If I now define a new object using this structure, is there a way to query through each of its 'children' eg, Dim Team as New Players() Dim i as Integer = 1 ' Some code to find Team.Players1 since i = 1 but if i = 2, then use Team.Players2. ' Then I can jump to a function specific to what player is current. Team.Player?? (the one that matches to i) then do something else. The way I am thinking about this is the same way you would loop through all of the controls on a form and look for a match in the controls name or text. I know I could do it with a Select Case or If statements, but I am trying to do it without having to code a few hundreds lines. Thanks Steve Quote
Administrators PlausiblyDamp Posted February 5, 2004 Administrators Posted February 5, 2004 Rather than a structure could you not use an array of Players? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
sjn78 Posted February 6, 2004 Author Posted February 6, 2004 I thought about that and will most likely go that way, but can you still do what I asked in the previous post?? Quote
*Experts* Nerseus Posted February 6, 2004 *Experts* Posted February 6, 2004 You could probably use reflection to build up a string of "Player1" and find the actual property, but I don't think it's a very good design. There are SO many other, better options. A hashtable, for instance, allows storing data and finding it by a string name. If you really want to find a control by "name" (meaning, the string translates into the actual control name) it can be done. For finding fields in a struct, I would think this is a last resort. -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.