LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert strings from input string control into a 1D array

Solved!
Go to solution

I'm doing a program where I constantly write strings into a string control. When I write one, I press enter and the string I introduced gets erased from the string control and then appears in a string indicator. I want to append all those strings I introduce into a 1D array but I can't seem to figure it out, I initialize an array in blank spaces and then replace the specific element, but my problem is the index, I don't know from where to create an iteration that represents each time I press enter in my string control input. Any ideas?

0 Kudos
Message 1 of 9
(4,913 Views)

@aatm1412 wrote:

I want to append all those strings I introduce into a 1D array but I can't seem to figure it out, I initialize an array in blank spaces and then replace the specific element, but my problem is the index, I don't know from where to create an iteration that represents each time I press enter in my string control input. Any ideas?


Unless you actually attach your VI, we cannot figure out what you are doing wrong either.

 

To append an element to the end of a 1D array, you would use "built array" resized to two inputs, with the original 1D array wired on top and the scalar new element wired to the  bottom input. No need to worry about indices. Start with an empty 1D array.

 

Only if you know the final size, you can initialize a sufficiently large array of empty strings. In this case you can keep track of the insert point using a shift register.

 

Make sure to set the string control to "limit to single line".

 

0 Kudos
Message 2 of 9
(4,891 Views)

Sorry for that, this is my VI.

 

Thank you for the information. But, what original 1D array are you refering to? there's no array at the beginning, every element comes from pressing the "Enter" button.

0 Kudos
Message 3 of 9
(4,885 Views)

As I said, start with an empty array.

 

What is the rest of your code supposed to do? seems overly convoluted.

0 Kudos
Message 4 of 9
(4,858 Views)

What the code does is receiving strings from the input control, this strings are then saved or stored into a text file (like a very simple data base), and after a specific number of strings introduced it has to determine if I've introduced a repeated string (with a pop-up notifying such, then continuing when clicking "OK"), that's why I want to introduce the elements to an array, to search for the strings using the Search 1D Array function, instead of reading from the same file created, therefore it's easier to manipulate everything. The huge for loop you see in the right side of the block diagram is what tells me the number of strings that have been repeated during the simulation.

0 Kudos
Message 5 of 9
(4,854 Views)

Not sure why you need to save anything in a file. Is that for record-keeping? The string array is right there for duplicate testing.

Do you just want to tell if any of the strings occurs more than once or do you also want to determine how many times each string is repeated?

 

Unless the string arrays get extremely large, you can do the duplicate check right in the event case. (Note that LabVIEW 2019 has sets, which would greatly simplify the determination of duplicates). You could even check and not add it to the end of the array if it already exists, automatically keeping all elements unique.

0 Kudos
Message 6 of 9
(4,848 Views)

Here's one possibility to count the number of duplicates. No need to wait for a certain amount or pop dialogs. See if you understand it.

 

With code, often less is more.

 

altenbach_0-1589729520391.png

 

0 Kudos
Message 7 of 9
(4,811 Views)

Yes, saving in a file is for record-keeping. I want the user to be notified if the string they've introduced has already been introduced before so I would like to tell if a string occurs more than once, but the program to continue.

 

Once again, thank you for the information.

0 Kudos
Message 8 of 9
(4,794 Views)
Solution
Accepted by topic author aatm1412

@aatm1412 wrote:

Yes, saving in a file is for record-keeping. I want the user to be notified if the string they've introduced has already been introduced before so I would like to tell if a string occurs more than once, but the program to continue.


 

So put the "built array" inside a case structure. If the item exists, notify the user and don't add it. If it does not exist, just add it.

 

altenbach_0-1589739599765.png

 

0 Kudos
Message 9 of 9
(4,785 Views)