From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case statement from array elements

Hi All,

 

Can anyone suggest a simple way of selecting a case based on the position of array elements.

 

E.g - First position in array calls case 1, last position in array calls case 2, everything else case 3.

 

Thank You

0 Kudos
Message 1 of 9
(4,380 Views)

This problem is, on the one hand, almost trivial (provided you know some things about the Array, such as its size so you can identify the Last Element), and confusing (is the Array "known in advance", "being generated", "something else"?).

 

This would be a perfect time for you to have written some code to get yourself started, realized "Oops, I don't know how to ...", attached your code (so we have a clue what you are really trying to do), and then asked for help.

 

Why don't you try that?  You might even be able to "do it yourself" ...

 

Bob Schor

0 Kudos
Message 2 of 9
(4,373 Views)

It feels like you're leaving out some information here.

 

Do you have an array containing some values, and another value as input, and you're looking to see if it matches the first or last elements and then choosing a case based on that?

 

Or are you doing a FOR loop that indexes every element of an array and you want the first and last iterations to have a special case?

 

Or is it another situation entirely?

0 Kudos
Message 3 of 9
(4,372 Views)

Autoindex your array on a FOR loop containing a case structure wired to the iteration terminal.

 

(I am sure there are much better solutions to your problem. What are you trying to do?)

0 Kudos
Message 4 of 9
(4,358 Views)

Hi All,

 

sorry for the poor description of my problem. As you have probably guessed I am learning Labview. In hindsight I should have explained better.

 

I have an array of type string going into a FOR loop (auto indexing) and I want to put a case statement inside the for loop to format the string depending on if its the first element, last element or anything in between. The size of the array is not known.

 

I have found an answer for first and last element in the array using array size then comparing it to the Loop counter.  Ideally I was looking for a neat solution to do all three within a single FOR loop.

 

ThanksArray_Case_Select.png

0 Kudos
Message 5 of 9
(4,313 Views)

i am paraphrasing Bob-no-images-we-are-not-british-Shor:

please attach code not images.

if you don't want to attach your whole VI, create a new one showing only the part where you have a problem with (which is always a good choice).

 

regards

 

EDIT: for your consideration (and to help you help us help you)

https://forums.ni.com/t5/Community-Documents/Unofficial-Forum-Rules-and-Guidelines/ta-p/3536495


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 6 of 9
(4,308 Views)

Hi, is something like this would solve your problem ?array_to_case.png

 (This is a snippet, you can drag it into your vi to test it).

 

Edit : With the snippet attached as suggested by jwscs

Message 7 of 9
(4,298 Views)

hi Arik.v³

unfortunately, you also have to attach the snippet .png,

with the new forum design, they messed up the drag+drop directly from the image,

so the original file is needed.

(see Notice at top of the forum https://forums.ni.com/t5/LabVIEW/Notice-Attach-VI-Snippets-to-post-rather-than-upload/td-p/3660471)

 

regards

 

EDIT: ok it is not really necessary as more a convenience

if you right clikc on the image and "View Image" (or somesuch) you get a link like this

/t5/image/serverpage/image-id/232256i4F1EFB6A0F27AC90/image-size/large?v=1.0&px=999

if you remove the "/image-size/....." part

/t5/image/serverpage/image-id/232256i4F1EFB6A0F27AC90

you can then drag+drop it


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
Message 8 of 9
(4,291 Views)

Hi Jwscs,

Thanks for the remark, I made an edit on my previous post to attach the snippet.

0 Kudos
Message 9 of 9
(4,279 Views)