02-12-2020 11:11 AM
I'm new to LabVIEW and am stuck on something that I thought should be pretty easy to accomplish. I have a form wtih about 50 controls on it. I can loop through these controls and write their values to a text file without a problem. This is done in a way that I can add or remove controls and the code to generate the text file doesn't need to change.
I can also read this file in and parse it up without any problems. However, nothing I have tried gets the controls populated. I've attached my current code and the text file I'm reading from. Does anybody have any suggestions on how to accomplish this?
My code to read and write the text file is attached. Thank you.
Solved! Go to Solution.
02-12-2020 11:33 AM
Hi wvfrc,
Personally, I like to use the MGI Read/Write Anything library for configuration files. You can find this on VIPM. Some comments on your code:
1. In LoopThroughTab.vi get rid of Open/Create/Replace File. It is already called inside Write Delimited Spreadsheet.
2. Get rid of Array to Spreadsheet String. You can feed your data array directly into Write Delimited Spreadsheet.
3. This will only capture the controls that are inside the tab. The ones not in the Tab control are excluded.
4. In PopulateControlsFromCSV.vi it looks like you take column 0 and look for a label match. However, in the file you uploaded, it is actually row 0 that contains your labels.
02-12-2020 11:45 AM - edited 02-12-2020 11:46 AM
One of your problems is that you are looping on both the rows in the file and the control references. You need to turn off the Autoindexing tunnel on the 2D String Array. That will mess up the Index Arrays you have inside of the loop.
The other major issue you have is that you are overwriting the File Path with the "Reinitialize All To Default". You probably should not be using that function. At the very least, you need to make sure you are reading the path terminal before that method is called.
I took the liberty of doing some major cleanup of your code.
02-12-2020 11:55 AM
Thank you for your input, and that is exactly what I was looking for. I knew that there was some major code cleanup needed and really do appreciate your input.
02-12-2020 11:58 AM - edited 02-12-2020 11:59 AM
Thanks for your input. I just cleaned up some of the code based on your suggestions too. The tab control was what was in the original form, but I removed it just to simplify my testing. I also downloaded MGI Read/Write Anything as well and will definitely take a look at this.