04-24-2020 10:20 AM
hi
in my code bellow i have three adjustable numbers and three array indicators.in the case structure user can choose number between 0 to 2 and depends on the number the 3 adjustable numbers going in array 1 or 2 or 3.
for example user chooses adjustable numbers 3 4 5 and also chooses case structure 0 by pressing add button these numbers go consecutive in the index 0 1 2 on array 1 and if the user push it again new number go to next indexes on array 1 and the previous data won't be lost.
now if the user chooses case 2 this process is done for array 2 without losing data on array 1.
my problem is here when i choose new case structure and press add button for the first time after choosing case my adjustable numbers go to my previous array ، my second press send it to array2.
can anyone help me?
Thankyou.
Solved! Go to Solution.
04-24-2020 12:16 PM - edited 04-24-2020 12:17 PM
You have a race condition because the numeric gets read before the event structure fires, so if you change it, the new value gets only applied at the next iteration. You also don't have an event for the stop button.
04-24-2020 12:19 PM
DataFlow!
Your Numeric indicator is read pretty much immediately when your loop iteration starts. Then it waits around at the event structure until the event happens. Even if you change the numeric value, it won't get read again until the next iteration.
The numeric terminal belongs in the even case so it isn't read until you press the Add button. You may have to rearrange other code like bringing the first case structure into the event case as well.
Run your code with highlight execution turned on so you can understand what is happening.
04-24-2020 12:37 PM
04-25-2020 09:20 AM
Thank you very very much
04-25-2020 09:52 AM - edited 04-25-2020 09:53 AM
Of course my solution is not really scalable and would become quite complicated if the number of arrays would need to be increased. Here is the same using arrays of controls and indicators.
(Since ragged 2D arrays are not possible, we need to do a 1D cluster array for the output.)
Here's how that could look like.
Now only very minor changes are needed to e.g. change the number of "hour" controls or the number of ragged columns.
04-25-2020 10:57 AM
this code is very good but what should i do if i want to access to each column data separated from each other.
how can i separate columns and access them in my block diagram?
04-25-2020 11:09 AM
@ehsan75 wrote:
this code is very good but what should i do if i want to access to each column data separated from each other.
how can i separate columns and access them in my block diagram?
Depends what you mean by "access". I am already "accessing" the data structure inside the event structure, so follow that pattern.
You can always index out and unbundle. Here's one possibility:
Of course if the rest of the code is aware of the data structures, you might not need any of that.
04-25-2020 11:27 AM
yes i meant index out and unbundle .
this code working but when i add numbers to one column same indexes of other columns become 0 . what to do to avoid this?
04-25-2020 03:28 PM - edited 04-25-2020 03:34 PM
@ehsan75 wrote:this code working but when i add numbers to one column same indexes of other columns become 0 . what to do to avoid this?
Since 2D arrays cannot be ragged, LabVIEW will pad to the longest. Just index out the cluster array and unbundle each separately if you like that better.
As I said, operate on the data in the structure. No need to "extract" anything, except maybe at the end for saving.