05-17-2020 12:58 AM
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?
Solved! Go to Solution.
05-17-2020 01:28 AM
@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".
05-17-2020 01:37 AM
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.
05-17-2020 02:07 AM
As I said, start with an empty array.
What is the rest of your code supposed to do? seems overly convoluted.
05-17-2020 02:25 AM
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.
05-17-2020 02:38 AM
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.
05-17-2020 10:35 AM
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.
05-17-2020 12:30 PM
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.
05-17-2020 01:20 PM
@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.