LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filling listbox with data from Text or Excel file

Hi!

My User interface has a listbox (single column) that needs to be filled with data from a text file OR excel file (excel prefered) each time the vi runs.

Once the listbox is populated, the user needs to select any ONE entry and continue with the vi. The selection string needs to be recorded at the end of the vi.

Thus I wish to know how to:
1) Fill my listbox with data from a .txt OR .xls file
2) Record the item (string data) selected by the user in above mentioned listbox.

I am using LV 6.1

Thanks and regards,
Gurdas
gurdas@qagetech.com
Gurdas Sandhu, Ph.D.
ORISE Research Fellow at US EPA
0 Kudos
Message 1 of 5
(6,785 Views)
Hi,
to fill list box with some data you must create its property node (right-click on item and select Create->Property node) and choose "Item names" property. This property is a 1D array of strings representing items of listbox. To add some item to the listbox you just need to add string to this array. To do it you can use functions from array palette such as "build array" or "Insert into array". To remove item use "Delete" function from array palette and so on.
So all that you need is to read some strings from your file (using functions from "File I/O" palette" and add them to the listbox "Item names" propery.

Here is an example of how to insert items into listbox.

Good luck.

Oleg Chutko.
Message 2 of 5
(6,785 Views)
In addition, there are two cases you can (and should deal with). The first is when the user selects an item and then clicks an "Ok" button or something similar to finalize the selection. In that case, the value of the control is the number of the item selected when the button was pressed. To get the text, use the value to index into the array you used to populate the property node.

The second thing is if the user doubleclicks an item. To use this you have to read the doubleclick property in your loop. In the value of this property is -1 it means there has been no doubleclicks. Anything other than -1 is the number of the item that was double clicked--which you can use as above.

Finally, it's also a good idea to initialize the value of the listbox to -1 w
hen the itemnames property is loaded. This has the effect of deselecting all items and isn't really necessary, but gives a cleaner interface and IMHO is just good housekeeping.

Also remember that although the listbox looks like some sort of text table, it's really a numeric control and it's value is a number.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 3 of 5
(6,785 Views)
Oleg and Mike: Thanks each!

I could easily implement Oleg's suggestions and do not see any hurdles in implementing Mike's.

However, I have a small issue to be resolved:

How do I clear my listbox of all data before reading my text file?

My listbox shows data accumulated from the previous runs of the vi. I tried using 'delete from array' with 'ItemNames' but am unable to do the desired. Is there a standard setting which allows me to initialise the ItemNames each time the vi runs?

Also, can you suggest me good books on exploring Property Nodes of functions in LV?

Best,
Gurdas
Gurdas Sandhu, Ph.D.
ORISE Research Fellow at US EPA
0 Kudos
Message 4 of 5
(6,785 Views)
Whenever you write a new array to itemnames it overwrites what's already there, so writing an empty array to the property before you application terminates will erase the old values.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 5 of 5
(6,785 Views)