Example Code

Selectively Add Items From List Box to an Array

Code and Documents

Attachment

Overview
This example VI shows how you could pass values into a list box, then have the user choose items from that list box to create an array that fits their needs.

 


Description
With this VI you can pass values into a list box, through the event structure the user can choose items from that list box , and then create an array that fits their needs.

 


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Unzip the attached folder to your computer
  2. Open the VI "Listbox Array 2012 NIVerified.vi"
  3. Edit listbox items, or pass values in by using this example as a subVI
  4. Run the program
  5. Double-click on listbox items to selectively add them to an array

 

Additional Information or References
VI Block Diagram

 Block Diagram.png

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

Matt J - NI Tools Network

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
matteci
Member
Member
on

I am concerned with appropriate memory management. Is this use of 'build array' going to cause any memory issues if looped for long periods of time? If so, can an example be provided of a functionally equivalent method without the memory concern?

Matt-J
NI Employee (retired)
on

hi matteci,

Since the build array function is called conditionally (i.e. only when someone double clicks on a listbox item) I would not worry about memory buildups. If you plan to tweak the functionality so items get added frequently, I would consider pre-allocating an array (initialize array function) with enough elements to cover your needs. You would then use insert into array or replace array element functions to avoid making copies of the array in memory.

Hope this helps.

Matt J - NI Tools Network
matteci
Member
Member
on

Thanks, that does help me understand.

Sorry if this isn't the best place to ask, but since I've already hooked ya... I have a question about how and where to initialize arrays used for this purpose. Can it happen in a case statement wired to a 'first call?' function? or is it preferable to make it happen outside the top loop? My RT application has vis nested several layers deep and I have yet to really understand the best style for initializing arrays in my use case.

Matt-J
NI Employee (retired)
on

Hi matteci,

I would suggest posting that question in the LabVIEW RT discussion forum, linked below.

http://forums.ni.com/t5/forums/searchpage/tab/message?submitted=true&type=message&q=rt&page_size=50&...

Matt J - NI Tools Network