LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using text file to initialize front panel controls

Solved!
Go to solution

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.

0 Kudos
Message 1 of 5
(2,712 Views)

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. 

 

0 Kudos
Message 2 of 5
(2,689 Views)
Solution
Accepted by topic author wvfrc

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Download All
0 Kudos
Message 3 of 5
(2,680 Views)

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.

0 Kudos
Message 4 of 5
(2,674 Views)

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.

0 Kudos
Message 5 of 5
(2,670 Views)