LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

making large case statements

Hey all,

 

Is there a better way for me to make a case statement that has over 400 cases? This is obviously an unreasonable amount of cases but I'm unsure of any other way.

 

Each case statement is very simple, depending on the matched string it passes out two numeric constants that are then used as indexes for an array. In the array is values that I want to be selected on a graph.  I've attached my VI. The array currently does not have any values, as you can see at the top I've tried to combine them given each "device" its own column.

 

Think of the array as a matrix. Each column is a different device, each device has either 4, 8, or 32 channels. The case statement is used to pick out which device, and which channel I want to see displayed on a graph.

 

Any ideas you guys can give me would be great. 

 

Thanks in advance

 

-Brad

0 Kudos
Message 1 of 6
(3,172 Views)

First, It looks like each of those case structures are identical.  So instead of having 8 of them, it would have been better to turn one of them into a subVI with a string input, and 2 numeric outputs, and use that subVI in each place you have the case structure.

 

But of course as you asked you want to also eliminate the huge number of cases.  What you really have going on is a lookup table.  I would make a couple of arrays.  One is a string array containing all of your strings.  The other is a 2 column multi row numeric array containing all of your numeric values.  Search the string array for your string, it will return and index.  Use that index with an index array on the numeric array to return the row.  Break out the 2 columns.

 

Of course put all of this decision making into a subVI.

 

You may also want to store all of these values in a text file and load the text file in at the beginning of the program to create the arrays.  This is one of those things that may be easier to create and edit in Excel and write out to a text file.  If you make a mistake or need to change something later, you just edit the text file rather than trying to sort through all of the indices of an array constant within the LabVIEW environment.

 

I am not sure what you are doing at the top of your loop with all of the insert into arrays.  It looks like incomplete code.  But Build array would probably be a better choice there.

Message 2 of 6
(3,167 Views)
It should also be pointed out that you have a race condition with the use of that local variable. LabVIEW does not execute code top-to-bottom (except for property nodes) or left-to-right. Thus, your attempt to read the "Measurements Array" via the local will not be synced with whatever you're doing at the top. Use a wire.
Message 3 of 6
(3,151 Views)

Hey thanks guys for your quick responses. My internet at work has been down so I haven't be able to reply until now.

 

I've went ahead and created an Excel spreadsheet file, with the first column all of the string cases, the second column, is the column index and the third column in the row index. Now I'm having trouble reading in the file. I just want to read in the first row and put all of that into an array. Then I want the second two column to be put into a 2 deminsional array. Then I want to search through that array based on an input, return the index of the match and then use that index to find the column and row index. Does this sound like a more efficient way to do this that one huge case statement? 

 

I've attached my VI and excel file, because I cannot seem to get the file to read in properly. Any suggestions you could give me would be great.

 

Thanks

 

-Brad

 

 

Download All
0 Kudos
Message 4 of 6
(3,116 Views)

You cannot use Read From Spreadsheet File to read Excel workbooks. The name of the function is misleading. It reads text files that have been formatted in a spreadsheet-like way. You can either:

(a) Save the Excel file as a tab-delimited text file. Then that code will work.

(b) Use ActiveX to automate Excel. This requires that you have Excel installed. Examples of how to do this ship with LabVIEW. Lots of other examples can be found in this forum as well as the "Excel thread". 

Message 5 of 6
(3,106 Views)

Thanks, your right. I just went a looked through the threads a found that. Should have look first.

 

Anyways I figured it out and everything is working great. Thanks for your help.

 

-Brad

0 Kudos
Message 6 of 6
(3,101 Views)