This is actually a program in LabVIEW
but I can write C
scripts in labview and /or simulate the same logic
in LabVIEW
as in C
. also to attract more answers. So I just need the algorithm mainly. Please read the entire question.
In my application I have 5 variables say:
var1 -> type string,
var2 -> type string,
var3 -> type array of strings,
var4 -> type array of strings,
var5 -> type boolean
Now these 5 variables control how I should filter the data I read from a file.
So for this I have a switch case which will do the actions based on these inputs.
To control the switch I do this:
false
.false
.false
.false
of true
.So I get a 5 bit combination so I can have 32 values, hence 32 types of filters i.e 32 cases!.
For e.g if var1
is empty, var2
is not empty, var3
is not empty, var4
is empty, var5
is true then I have 01101 (13 in dec). So I choose the 13th filter.
Coding this is really hectic so I want to collapse the number of cases. How to do it?
What i'm looking for is an algorithm.
here is the labview code
var1 -> operator name, var2->supervisor name, var3->JobID, var4-> Multiple batch select, var5->invalid date.
EDIT. ;
an e.g
if var1 and var3 are not null then i have to read the data from file such that it contains var1 and var2 data.
e.g 2
now if var1, var3, var5 are not null then i need to select data such that it will have data common to var1 and var3 and var5.
e.g 3
if i have var1,var3,var4,var5 i need to fetch data that containds data which is common to var1 var3 var4 var5.
e.g4
if i have just var3 i need to fetch only data related to var3.
There are a number of possibilities to do what you're asking/suggestions for improvement.
For each test you do, have a nested Case structure. A recommendation here: if you have certain tests that are more likely to fail, put them on the outside. That way you can optimize execution.
The Case structure you already have can handle multiple cases by using ranges. For example, you can handle the numbers 1 through 10 by typing 1..10 in the Case Selector box. You might be able to reduce the number of cases by making certain cases consecutive.
I'm not exactly sure which version of LabVIEW you're using, but some of the tests you're doing can be simplified a bit. For example, I believe in LabVIEW 2011 and later, there are special test-for-empty-array and test-for-empty-string functions that you can use.
Also, instead of using 5 Insert Into Array functions, try a single Build Array function that's expanded to hold the number of booleans you have.
I think "exponential increase" is the type of increase meant here, if you have more booleans. The number of cases (theoretically) is 2^(number of variables).