Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...