04-22-2020 12:40 PM
A project I am working on, starts with a .csv (like) file that I think needs to be indexed, re-sort the items, and create a three line output (with comma delimited) between them. The headers (line 2) and data (line 3). The index array works but the code is cumbersome to troubleshoot. There must be a better way to index values and create the text file; but I am not sure how it can be different.
Also, the array keeps the values if I attempt to process two files, without restarting the application? I tried to empty the array but occasionally the processing seems delayed and doesn't process the time to minutes correctly. Thanks for looking/reading.
Solved! Go to Solution.
04-22-2020 01:14 PM
@Rockets212 wrote:
The index array works but the code is cumbersome to troubleshoot. There must be a better way to index values and create the text file; but I am not sure how it can be different.
Holy cow, you weren't kidding. This block diagram is enormous... troubleshooting would be nearly impossible!
Without knowing your input file format and output file format it's hard to give you any real advice, other than "Index array" should probably only be on your diagram once.
If your format is based on row/column positions, then I'd probably create a struct typedef containing a row, column, and label. The label will be for easier handling, but you might not need it.
Put this into an array, then into a For loop indexing on this struct. Within the loop, do your Index Array and build up your "Output" array, which you can further manipulate or just concatenate.
You will need some way to store the "decoding" information. If it's rows and columns, use an array of rows and columns. If it's got labels (like "FilterID: [value]" then you can use string searching functions to just parse through the string to find the "identifier" then extract the next value.
04-22-2020 01:26 PM - edited 04-22-2020 01:36 PM
Thank you for the response. I will try these ideas.
The file format starts as .evt but opens as a .csv; it appears to be CSV.
I do need to index rows & column to create the header or label and the data associated to the heading.
I would then guess since its so large that the array isn't processing the time to minutes correctly due to its size also?
04-22-2020 01:52 PM
I would then guess since its so large that the array isn't processing the time to minutes correctly due to its size also?
No, that would probably be a race condition you have from using local variables. You are writing to "Hours to Minutes", "Minutes", and "Seconds" each iteration of the loop but also using local variables to read the same data. Which one will happen first is anyone's guess. The local variables could very well still have the data from the last loop iteration before the controls are updated (or whatever data is in the control on your first run). The wires are literally just a few inches from the variables, just use those instead!
04-22-2020 04:11 PM
@BertMcMahan wrote:
@Rockets212 wrote:
The index array works but the code is cumbersome to troubleshoot. There must be a better way to index values and create the text file; but I am not sure how it can be different.
Holy cow, you weren't kidding. This block diagram is enormous... troubleshooting would be nearly impossible!
Without knowing your input file format and output file format it's hard to give you any real advice, other than "Index array" should probably only be on your diagram once.
If your format is based on row/column positions, then I'd probably create a struct typedef containing a row, column, and label. The label will be for easier handling, but you might not need it.
Put this into an array, then into a For loop indexing on this struct. Within the loop, do your Index Array and build up your "Output" array, which you can further manipulate or just concatenate.
You will need some way to store the "decoding" information. If it's rows and columns, use an array of rows and columns. If it's got labels (like "FilterID: [value]" then you can use string searching functions to just parse through the string to find the "identifier" then extract the next value.
Here's an example of what Bert was suggesting. There is a for loop that can handle all the index arrays and concatenate functions. (I did the first line of your new output as an example.)
There is also some Rube Goldbergian code in there that could be cleaned up as well.
This -
does the exact same thing as this -
04-22-2020 04:22 PM
You should also check out the "Format Into String" function instead of using "Build String" with 4-5 inputs.
For example, if you have a a wire with the string "20" in it and you wanted to make that say "Max temp: 20 (C)", you could do that with a Format Into String with the Format being "Max temp: 20 (%s)", and it'll wire your string "20" into the spot it sees the "%s".
04-23-2020 03:52 AM
Instead of those gigantic Concatenate strings to create the comma separated row, create an array of the string and use a Format into Spreadsheet string with comma as separator. It'll more than half the needed wires (and thus the clutter).
Also, Sub-VIs are important!
04-23-2020 07:05 AM
It appears I haven't gotten the concept of smaller portions (SubVI's) to reduce the 'one size fits all' coding. I can see in this project that it created a big problem for me. Thanks to all for the help and responses.
I have a few questions; how did you make the Control item and use that in the VI?
Should I remove any other variables aside from re-wiring the time to minutes?
04-23-2020 08:09 AM
@Rockets212 wrote:Should I remove any other variables aside from re-wiring the time to minutes?
Based on what I quickly saw, you should not have any local variables.
So for some reason, I have had this thread in my head since last night. And I think I have come to the conclusion that I would attack this with 2 FOR loops. Each loop can run in parallel, each handling a different line in the final file. I would use an array of strings to state what is being handled for each item going into the line. Autoindex on those arrays and do whatever parsing, etc needs to be done inside of a case structure, and autoindex a string out of the loops. At this point, a FOR loop will output an array of strings. You then use Array To Spreadsheet String to convert into a comma delimited array and write the string.
04-23-2020 09:21 AM
E.g. instead of all that string manipulation to get the Elapsed time, you can do it like this: