george seifert Posted May 16, 2007 Report Share Posted May 16, 2007 I'm converting a C program to LV. There are at least a hundred defines that I need to deal with. I'm wondering if it's better to build a big cluster that contains all of them or use a two dimensional array that has the name and associated value. When I need to use one of the variables from the defines then if I use a cluster I would match up the variable name with the cluster label and grab the value. Or if I use the array approach I would need to find the index of matching name and then use that index to grab the value. I can't decide which way is better. Any thoughts? George Quote Link to comment
Yair Posted May 16, 2007 Report Share Posted May 16, 2007 I would say that of the two you would be better off with the cluster because it's named and so would be clearer. Other options - Globals. A seperate subVI for each. Rings or enums. Quote Link to comment
dthomson Posted May 16, 2007 Report Share Posted May 16, 2007 George, How about making an enum with all the names, and a matching array of values. On your block diagram, drop enum constants and set them to show the name of the item you want, then use that to index the array of values. It depends on how you are using the names. If you need to have strings for names, then it gets awkward, since you would need to match the string to either an array of strings or the string array of the above-mentioned enum. To get a bit obscure, I wonder if you couldn't make a polymorphic VI and use the click-able name below the VI Icon to choose an instance, each instance being a different constant. It would label the block diagram object with the name of the constant you are using, and it would condense everything into a single icon, rather than having a name index and array. There are probably other clever ways of packaging up, too... Dave QUOTE(george seifert @ May 15 2007, 07:38 AM) I'm converting a C program to LV. There are at least a hundred defines that I need to deal with. I'm wondering if it's better to build a big cluster that contains all of them or use a two dimensional array that has the name and associated value. When I need to use one of the variables from the defines then if I use a cluster I would match up the variable name with the cluster label and grab the value. Or if I use the array approach I would need to find the index of matching name and then use that index to grab the value. I can't decide which way is better. Any thoughts?George Quote Link to comment
Yair Posted May 16, 2007 Report Share Posted May 16, 2007 QUOTE(dthomson @ May 15 2007, 08:53 PM) George,How about making an enum with all the names, and a matching array of values. I would do that in one of two ways - either create a subVI which will have the enum as an input and the text as an output (with an internal case structure) and make a merge VI for it so that it will be easy to drop on the BD during development or I would have the string as the enum item and wire the enum into the Format Into String primitive. That would convert the enum value to its text. Quote Link to comment
george seifert Posted May 16, 2007 Author Report Share Posted May 16, 2007 Thanks for the ideas. I actually settled on a combo box. I keep forgetting about those things. George Quote Link to comment
Ton Plomp Posted May 17, 2007 Report Share Posted May 17, 2007 Hi, What about a variant with properties (or so called sets) Looks like just the right thing (automatic lookup) Ton Quote Link to comment
george seifert Posted May 17, 2007 Author Report Share Posted May 17, 2007 QUOTE(tcplomp @ May 15 2007, 11:34 PM) What about a variant with properties (or so called http://forums.ni.com/ni/board/message?board.id=170&message.id=234871&jump=true' target="_blank">sets)Looks like just the right thing (automatic lookup) Ton Are there any examples of that? I'm somewhat familiar with using variants, but I'm not quite sure how that would work. George Quote Link to comment
Ton Plomp Posted May 17, 2007 Report Share Posted May 17, 2007 I'll post somethign tonight Quote Link to comment
Ton Plomp Posted May 17, 2007 Report Share Posted May 17, 2007 QUOTE(tcplomp @ May 16 2007, 02:33 PM) I'll post somethign tonight Here it is, as a LV2 global. You'll probably miss one VI and some Typedefs, but the idea should be clear. Ton Quote Link to comment
george seifert Posted May 17, 2007 Author Report Share Posted May 17, 2007 QUOTE(tcplomp @ May 16 2007, 01:40 PM) Here it is, as a LV2 global.You'll probably miss one VI and some Typedefs, but the idea should be clear. Ton Thanks, but I must be dense because I can't really see how that relates to my problem. Actually it doesn't matter too much because the combo box is working pretty good. George Quote Link to comment
Ton Plomp Posted May 18, 2007 Report Share Posted May 18, 2007 My VI was a little bit overwhelming because I used it to store Tree data... But here is a slimmed version: http://forums.lavag.org/index.php?act=attach&type=post&id=5891 It looks a bit like the array approach you were going for, but you use the variant to store your data in, it behaves like a Database. Thanks to Tomi for giving the info. Good luck, Ton Quote Link to comment
george seifert Posted May 18, 2007 Author Report Share Posted May 18, 2007 quote name='tcplomp' date='May 17 2007, 04:06 AM' post='30237'] It looks a bit like the array approach you were going for, but you use the variant to store your data in, it behaves like a Database. Thanks to Tomi for giving the info. Good luck, Ton OK, I see how it works now. Interesting approach. I guess the only thing I don't like about is you can't easily edit the values in variant. I'd like to be able to easily go in and change one of the values and then have the results as my new "database". I don't think I can do that with the variant approach without running a VI. I've attached my Combobox to show you what I came up with. http://forums.lavag.org/index.php?act=attach&type=post&id=5893 Whereever I need to get a value I just drop an instance of the combobox on the DB. George Quote Link to comment
Yair Posted May 18, 2007 Report Share Posted May 18, 2007 I thought of mentioning combo boxes with rings and enums, but it seems that changing an element in the typedef does not update the list in the BD constant, losing the point of using the typedef. Does it work for you? Never mind, I just saw the other thread now. Quote Link to comment
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.