From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to check and verify the element/content in the array?

Hello...

Does anyone know how to check and verify the elements/contents in the array so that it will stop the user from entering the same data to the array?

To elaborate further, I have an array of cluster. The cluster contains some strings and some numeric data.

1. When the program runs, a file that contain some data shall be loaded into the array and display onto a menu ring (1st tab control interface) for user to access and select them.

2. User enter some strings and numeric data on (2nd tab control interface). User click Énter button and the elements are stored to the array and update to the menu ring.

3. But, how can I compare the new data with the data in the array (before write to the arr
ay) so that it will not add the same element to the array?

Example:

Data in the array (array of cluster):

String:String Numeric:Numeric
Voltage1:Current1 14.5: 25
Voltage2:Current2 14.7: 23

New data entered:

String:String Numeric:Numeric
Voltage1:Current1 13.5: 35 ---- (OK)
Voltage1:Current1 14.5: 25 -> (not OK, same data)

Do you know what Vi can be used to do this?

Please help.

Gracias,
woo
0 Kudos
Message 1 of 4
(5,411 Views)
Hello woo,

Before you add a new element to the array, use the "Search 1D Array" function to first check if the element already exists.

Regards,

Doug Norman
0 Kudos
Message 2 of 4
(5,411 Views)
Hello Doug,

Thanks for tip on using "Search 1 D array". I manage
to search the element out. At the output, ("index the element"), I wired it to a CASE STATEMENT.

At this point, could you please me give some guides here.

If the element is not already in the array, I would like to add straight away to the array.

But if the element (same string, same numeric data) is already in the array, I would like to let the user know what to do next. The condition shall let him do "Replace" or "Cancel" and key in again the data (different string and data).


Could you please help me out here.
I have attached a snapshot of my program to demonstrate my problem.

Thanks again,
woo
0 Kudos
Message 3 of 4
(5,411 Views)
Hi,
one possible solution is to use an intermediate array. The intermediate array should be used in the user interface. When new data is entered the VI should read each element and then compare to the elements in the stored array. If all elements are different then update the array, otherwise display a fault message.

You could use asequence activated when the Enter button is pressed. In the first frame you would compare the First array with the stored array. it is probably best to use a Boolean indicator to show if the data is valid Make sure you declare this as a local variable.

With the sequence you can perform the comparisons in several seperate frames or in one frame with a OR to link the results. For large numbers of comparisons I prefer to use m
ultiple frames because otherwise the screen becomes a maze of wires and other programmers who may need to maintain the code in the future will find it hard to follow a single frame.

Once all the data items have been compared then the following sequence should contain a CASE statement of type True/False. Link a readable copy of your local variable to the selector of this statement. Then in the FALSE case (Assuming you have linked the boolean to be false when no data is duplicated) copy the new array to the stored array. In the TRUE case bring up an error message.

So long as your arrays are not too large and you do not use this technique in too many places in your code the processor overhead should not be badly affected. For frequent use of such a caomparison in several VIs you may want to create a dedicated subVI for the task. For very large arrays you should seek a different solution.

Hope that helps a bit.

Good luck,
Shaf
0 Kudos
Message 4 of 4
(5,411 Views)