10-12-2020 11:16 AM
Hi All,
I'm relatively new to LV and am struggling with the logic behind a concept.
The program attached aims to:
1) Generates a 1x5 1D array when the "OK" button is pressed.
2) Adds a new 1x5 1D array into a 2D array beneath the previous array when "OK" is pressed again.
3) Changes an n-index array when "RETEST" is pressed, where n is given by a numeric control.
4) Continues to add a 1x5 1D array beneath the last array after "RETEST" has complete and "OK" is pressed again.
The issues with this program:
1) The FOR loop count (e.g. 4) is meant to define the number of numeric arrays there should be in total. When RETESTing, the FOR loop increments, even though it replaces the correct array. So, if I need an 10x5 numerical array I will "OK" 9 times, then need to "RETEST" 1 time, then the FOR loop ends and there is a 9x5 numerical array.
2) After doing a "RETEST", pressing the "OK" is meant to give a 1x5 numerical array where index 0 is n-1 row. However, as I've linked the FOR loop increment with the 0th element and issue 1) occurs, the outcome when I "RETEST" once is:
test0 test1 test2 test3 test4
1 x x x x
2 x x x x
3 x x x x
4 x x x x
6 x x x x
Is there a method of achieving the aim with a FOR loop and fixing the issues or will an entirely new method be required?
Solved! Go to Solution.
10-12-2020 11:58 AM
1. Because of the retest capability, you should NOT be using a FOR loop: You should be using a WHILE loop. The retest means you do not know how many times you will be performing this action; therefore use a WHILE loop. Also with this, you cannot rely on the iteration terminal (the 'i'). Instead, you need to keep the current test iteration in a Shift Register.
2. Learn to use an Event Structure. It will make your life A LOT easier.
10-12-2020 01:18 PM
@SDuffyLV wrote:
I'm relatively new to LV and am struggling with the logic behind a concept.
Time to hit the reset button and learn about dataflow, state machine architecture, and proper coding practices.
In addition to what has already been said:
10-12-2020 01:56 PM
Here's a quick code skeleton that can hopefully give you some ideas. (Arguably simpler ;))
Lots of things can be improved, but start with that.
10-12-2020 02:18 PM
Good advice, thank you.
I was debating using Event structures but couldn't get them working on an initial setup and moved to the FOR loop method.
10-12-2020 02:26 PM
Yes, this is going to take some time to get used to the state machine architecture. However, I'm learning the LV Core 1 course, so this should certainly help.
Wow, that's surprising how wrong I went with this design. I really appreciate the input with this. It's a good learning curve.
There's supposed to be 1x column header for the titles "test0, test1...". I see the duplication could be unnecessary but was convenient for my method at the time.
V is just a placeholder name that defines the part of title of the csv to be created.
10-12-2020 02:44 PM
This is PRECISELY what I was aiming to do. It's surprising how much more simplified and clean this code is compared to my original one.
I'm going to extend this to have a hard limit on the quantity of rows for completion of my aims (or just make Test invisible when a certain quantity is reached).
Massive kudos for this. It's greatly appreciated!