# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Assigning string values to each numerical value of an array

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?

Message 1 of 11
(2,332 Views)
Solution
Accepted by topic author jrkh8er20

## Re: Assigning string values to each numerical value of an array

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.

 Example:

-Matt
Message 2 of 11
(2,325 Views)

## Re: Assigning string values to each numerical value of an array

That worked perfectly, thanks!

Message 3 of 11
(2,304 Views)

## Re: Assigning string values to each numerical value of an array

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.

Message 4 of 11
(2,233 Views)

## Re: Assigning string values to each numerical value of an array

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
Message 5 of 11
(2,226 Views)

## Re: Assigning string values to each numerical value of an array

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.

Message 6 of 11
(2,215 Views)

## Re: Assigning string values to each numerical value of an array

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.

-Matt
Message 7 of 11
(2,193 Views)

## Re: Assigning string values to each numerical value of an array

Thank you very much. It worked perfectly.

Message 8 of 11
(2,183 Views)

## Re: Assigning string values to each numerical value of an array

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

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

(Look ma no case struscture to hide code in)

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

## Re: Assigning string values to each numerical value of an array

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

Message 10 of 11
(2,166 Views)