Structures within Structures - can it be done?
vegastech
Posts: 369
I have created a structure to hold channel presets, with a name and a number. No problem. The thing I can't quite wrap my head around is how to create a structure WITHIN a structure. I was hoping to be able to create another structure to contain 6 different users each with their own custom presets, but when i tried to do it, I locked up not only Netlinx studio, but my PC as well, effectively corrupting the project and forcing me to extract from the src file. So...I really don't want that to happen again. I tried something like this:
I then tried to create a structure within a structure:
STRUCTURE _tvpreset //preset info { CHAR sChanName[15] INTEGER nChanNum } DEFINE_VARIABLE PERSISTENT _tvpreset uSATPresets[20] //20 presets to store #swhich gave me a structure with 2 elements(1 name, 1 number) to start with.
I then tried to create a structure within a structure:
STRUCTURE _users { _tvpreset uTVusers //creating a data type already identified in a prior structure CHAR sName //to describe the person selecting the presets info }It seems like it is possible, but am I looking at this backwards or something?
0
Comments
The last structure contains all the previous declared structures which could also include structures if there was a need. I'm not sure how deep you can go but you can go pretty deep. It just makes writing a variable really, really long.
I tend to go lightly with it though; referencing an element three-four levels deep can get dang confusing, especially if you are working with arrays of structures (like I usually am). I find for simplicity's sake it's often easier to keep it at two levels, tops.
I agree with this. My poor addled brain gets lost in the endless dots and [] when working with the variables. I find that keeping them separate keeps me saner when in the program itself.
Every time you declare 300 variables at the top of a file there's a puppy massacre.
I much prefer embedded structures as it's so much easier to keep context and group related data. Maybe that's just me attempting to cling to anything that remotely resembles object orientation though.