From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

FIRST Robotics Competition Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Loading values on a control

Hello all,

I need to load an array of strings from a file (ex: text file, each row is a string), edit the array (modify strings, add/remove strings), and save it back to a file.

I need somehow to read the content of the file in a "string array" control, in order to edit it.

Is there a way?

Thank you very much

0 Kudos
Message 1 of 6
(8,943 Views)

I was just playing around with this yesterday.. strange coincedence?

Labview is great for this stuff!

My application was to read text lines from a file, encode them, then write them back out.

I read a text file into an array. Each line became an indexed string in the array.

I could then use array operations to manipulate each line string independantly and put it back into the array.

Then you can simply write the array back to a file (or even overwrite the same file).

Here's how I did it..

From the File-IO-Pallete :"Read Text File"

This will read a text file into an automatically dimensioned array of strings.

Read the "help" info for parameter settings

I just used -1 for the count so it would read the entire file.

Once placed on your diagram you have to "right click" on the function block and select "Read Lines" attribute.

It will automatically prompt you for the file name or you can pass a file pointer to it if your application already has the file open.

Then just right click on the output "text" connection and select " Create>Control". This will create an array of strings.

(I love this automatic type casting of labview.. too cool)

Thats it.. you have an array of strings from the file that you can manipulate!

For example.. to get a line from the array ... from the "Array Pallete" use the function "Index Array".

Then when done.. use the function "Write Text File" to write the file back out.

I saved the original file path and passed it to the "Write Text File" function so I didn't have to re-open the same file.

I'm attaching my applicaton with the exception of the "encoding functon" that you can ignore.

Let me know if this helps.

0 Kudos
Message 2 of 6
(3,109 Views)

Hello TeslaRules,

and thank you very much for replying!

Unfortunately, unless I haven't badly understood your suggestion, this is not the reply I was looking for... after I have created the control (as suggested), I have two independent items: the control and the indicator!

My application should:

1) Read the strings array from a file, and show'em on a indicator (and this is correctly done)

2) Edit the array, as it was a control

3) Elaborate the strings (My array is a list of SPI commands, that are sent to an external device)

4) Optionally, save the modified array back to a file

Thanks again, regards

0 Kudos
Message 3 of 6
(3,109 Views)

Well maybe the answer is simpler then.

The array can be manipulated whether it is a control or indicator.

This is done by using local variables.

Simply create a local variable to the array. (you can right click on you array control or indicator and follow the menus to "create> local variable" then place the local variable on your block diagram and click on it to set it to read or write mode.

If you want to write to the array make the local variable writable.

If you want to read from the array make the local variable readable.

I doesn't matter if the array is a control or indicator!

Hope this helps...

0 Kudos
Message 4 of 6
(3,109 Views)

IT WORKED!!!

Many thanks!!!

0 Kudos
Message 5 of 6
(3,109 Views)
Here's a better way to write the same thing. Sorry... the subVI called "Strencode.vi" is missing
0 Kudos
Message 6 of 6
(3,109 Views)