Jump to content

Keep numeric definitions in a big cluster or 2D array?


Recommended Posts

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

Link to comment

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

Link to comment

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.

Link to comment

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

Link to comment

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

Link to comment

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.

Link to comment

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...

Important Information

By using this site, you agree to our Terms of Use.