LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Assigning string values to each numerical value of an array

Solved!
Go to solution

I'm working on a project to create an "opening hand simulator" for a Magic: the Gathering deck. In my head, the idea is that I create a VI to shuffle a 60-card deck and display the top seven cards.

 

Well, I have the first part working fine - I have a VI that creates an array with values from 0 to 59, randomizes it, and then displays the first 7 values of the array. In other words, I hit Run and it spits out seven random numbers from 0-59 with no duplicates, just like if you shuffle a 60-card deck and draw seven cards.

 

But I want to go a step further and assign a string value (the name of a Magic card) to each numerical value in the array - so, 0 = "Island", 1 = "Lightning Bolt", and so on. That way when I hit Run, I will get a display of seven card names instead of seven numbers.

 

So, how would I go about 1) assigning a string value of my choice to each of the 60 numerical values in this array, and 2) display the values of this randomized array as the aforementioned string values?

0 Kudos
Message 1 of 11
(4,870 Views)
Solution
Accepted by jrkh8er20

Several options here, but the easiest i see is to use the numerical values to localize an array of strings. So have a separate array of strings, and use the numerical values to index the array and pull the string at that index value.

 

[edit] Example:Card Shuffle.png



-Matt
Message 2 of 11
(4,863 Views)

That worked perfectly, thanks!

0 Kudos
Message 3 of 11
(4,842 Views)

hi, taking advantage of your suggestion... what if i have an array of a hundred strings but in my front painel i just want to display 4 strings that will be selected automatically. in my cases the strings in my front painel will be alarms, so i have a hundred possible alarm messages that shall be displayed when the corresponding boolean is set true.

thank you.

 

0 Kudos
Message 4 of 11
(4,771 Views)

Can you pose a snippet of your most recent code? Add some comments to Portray what you're trying to accomplish. I'm just a little confused what you're trying to do. 



-Matt
0 Kudos
Message 5 of 11
(4,764 Views)

Hi, i am sending an example describing what i want to do. And rembering that i don't know if my approach is the best one, so if you have a solution using other elements it will be welcome.

thank you in advance.

0 Kudos
Message 6 of 11
(4,753 Views)

I would try something like this. You had several alarm elements, i just put those into an array, arrays are generally much easier to work with than several of the same type elements.  

 

Alarm true case.PNG

Alarm False Case.PNG



-Matt
Message 7 of 11
(4,731 Views)

Thank you very much. It worked perfectly.

0 Kudos
Message 8 of 11
(4,721 Views)

@Wolleee wrote:

I would try something like this. You had several alarm elements, i just put those into an array, arrays are generally much easier to work with than several of the same type elements.  

 

Alarm true case.PNG

Alarm False Case.PNG


Use an enum type def and those strings can travel places without having to update the string array constants in several places each time you add a new alarm

Capture.PNG

(Look ma no case struscture to hide code in)


"Should be" isn't "Is" -Jay
Message 9 of 11
(4,716 Views)

Thank you too, i'll try. I never saw this conditional tunel, looks interesting.

0 Kudos
Message 10 of 11
(4,704 Views)