Jump to content

Passing an array out of a case structure


Zalon

Recommended Posts

Hello again,

I recently created a topic asking the same question, but it has disappeared, i hope that it wasnt deleted due to me posting in the wrong forum?

But anyways, my question is regarding how i can pass an array out of a case structure, i would like to hear some other options, i havnt been working with labview for that long, and the way i currently do it - looks a bit evil to me.

This is how i've done it so far, using a local variable:

post-10844-1203929889.png?width=400

Thanks in advance

Link to comment

Thanks alot,

I had seen those shift registers on screenshots before, but i did not know what they were called, or what they exactly did, i have changed my function to use this instead.

First i tried setting the wire out of the case to "use default if unwired", but then i figured that the false statement should just wire the to wire entrances, is this the correct way to do it?

Link to comment

Ok, good.

Another thing is that when using the local variable together with the array indicator, the array is kept in memory, and when i run the function again the old values will still be in the array the function returns.

How should i empty it? Should i do it when calling the function? Set the array to an empty constant in a sequence inside the function? Or some other way?

Hope it makes sense

Edit:

I replaced the local variable with an empty control instead, that does what i wanted it to do, but is that the correct way to do it?

Link to comment

QUOTE(Zalon @ Feb 25 2008, 08:46 AM)

Ok, good.

Another thing is that when using the local variable together with the array indicator, the array is kept in memory, and when i run the function again the old values will still be in the array the function returns.

How should i empty it? Should i do it when calling the function? Set the array to an empty constant in a sequence inside the function? Or some other way?

Hope it makes sense

Edit:

I replaced the local variable with an empty control instead, that does what i wanted it to do, but is that the correct way to do it?

This is almost the correct way to do it, but you should probably replace the empty control with a block diagram constant. Right click on the control and choose "change to constant."

Link to comment

QUOTE(ned @ Feb 25 2008, 02:59 PM)

This is almost the correct way to do it, but you should probably replace the empty control with a block diagram constant. Right click on the control and choose "change to constant."

Hehe, yeah i did that at first, but i don't like the look of the constant in the Block Diagram view :)

But you are right, it should be a constant, so thats what i'll use.

Link to comment

QUOTE(Zalon @ Feb 25 2008, 06:14 AM)

Hehe, yeah i did that at first, but i don't like the look of the constant in the Block Diagram view :)

But you are right, it should be a constant, so thats what i'll use.

If you have a large structure that looks 'bad' as a BD constant, try instead making a sub-vi that has nothing in it except an indicator of your data type. Then when you place this on the BD, it does not take up as much space. I also recommend you name this VI something like "CONSTANT - my data.vi" and you make the datatype a type-def.

For smaller cluster constants that don't look 'good' on the BD, try changing the orientation by right clicking on the border and changing the to 'arrange by - horizontal'.

I always make type-defs of and data-type that is not a LV simple type. I also always make a type-def out of all enums. It is a good practice to get into.

Link to comment

QUOTE(Zalon @ Feb 25 2008, 07:14 AM)

Hehe, yeah i did that at first, but i don't like the look of the constant in the Block Diagram view :)

One way to clean up your diagram in this case is to create the constant as ned recommended, then select the constant on the block diagram and do Edit >> Create SubVI. This will encapsulate the (potentially ugly) constant into a nice clean subVI. You can then make an informative icon for the subVI and save it with a descriptive name, like "Empty Array Constant.vi". I do this regularly for situations where I need a structure constant on the block diagram because I hate having ugly clusters or arrays clogging up my mojo.

EDIT: Hey, look, jlokanis & I think the same things at the same time!

Link to comment

QUOTE(Zalon @ Feb 25 2008, 06:14 AM)

Hehe, yeah i did that at first, but i don't like the look of the constant in the Block Diagram view :)

But you are right, it should be a constant, so thats what i'll use.

Another simple way of cleaning up an empty array constant is to hide the Index Display (right-click on it and de-select the Index Display in Visible Items). The array still has a border showing that it is an array. You have to use the data wire to verify how many dimensions it is, though.

Link to comment

QUOTE(JDave @ Feb 25 2008, 11:18 AM)

Another simple way of cleaning up an empty array constant is to hide the Index Display (right-click on it and de-select the Index Display in Visible Items). The array still has a border showing that it is an array. You have to use the data wire to verify how many dimensions it is, though.

A different way is to run the local variable into an Array Subset function with none of the other inputs (index or length) wired. You will always get an empty subarray out of that, which is fine for initializing your shift register. You may get a bit of a memory penalty on using the local variable, but 99.9% of the time it doesn't matter.

I usually use the block diagram constant (always a typedef!) crammed into a small sequence structure, rather than making a subvi, but the local variable trick is fine too.

Link to comment

QUOTE(jdunham @ Feb 25 2008, 01:10 PM)

A different way is to run the local variable into an Array Subset function with none of the other inputs (index or length) wired. You will always get an empty subarray out of that...

Don't you have to set the length to 0 to get an empty subarray? I just get the input array if all inputs to this function are unwired.

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.