Showing results for 
Search instead for 
Did you mean: 

initialize array control dimension

Go to solution

I am using LV 2009 SP1 and would like to create a 1D array control of fixed size.  The array elements are a type-defined cluster of varying data type controls (enum and boolean).  The array control will reside on a front panel and will be intialized with values via software, yet the user will have access to modify the array element values (i.e., modify the enum and boolean controls.  While the user has access to modify the array elements, I do not want the user to be able to add new elements to the array.  The array needs to have a vertical scroll bar since the number of elements when the array is initialized may be large and also may vary.  I am familiar with the "Number of rows" array property but this only controls the number of visible rows in the array.


Is there a way to fix the number of elements programmatically and still have a scroll bar for the user to index through the array, but not add new elements?


Please also see the attached screenshot for reference.




0 Kudos
Message 1 of 10

The following code (in LV2010) employs an event structure to capture when the array value is changed.  If the new array size does not match the old array size, the newly added element is deleted.  This keeps the array size the same as the original.  But any of the existing elements can be changed.  The code has local variables and size indicators throughout to show that the size of the array cannot be altered.  Use the parts of the code as you need.


- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 10

Sorry tbob, but this is kind of a messy way to deal with the issue.  Why even allow the user to try to add new elements if you are just going to delete them?


I only want to display a fixed number of elements and no more.  The UI should not seem to provide functionality that doesn't really exist.


Any other suggestions?



0 Kudos
Message 3 of 10

Yes its messy.  But do you know of another way to do it.  You cannot disable the array control because you want users to be able to change the elements.  There is no way to allow them to change, yet not allow them to add.

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 10

If I knew of a way i wouldn't be posting here.


Anyone else have a cleaner idea?


Please don't respond unless you can fully meet the requirements I have specified.  I already know how to almost get the functionality I want.



0 Kudos
Message 5 of 10

The only way I know of to add or delete elements from an array control is by way of the shortcut menu.  Do you need the right click menu for the array?


If not, use an event structure for the array for Shortcut Menu Activation? and wire a True to the discard terminal.


0 Kudos
Message 6 of 10
Accepted by topic author DBerry

I found an acceptable solution through reading some other forum posts. 


For others who may find this useful:

By hiding the array index display and all scrollbars, the array can be fixed in size.  A separate scrollbar control is used to index through the array by writing to the Index Values array property.  The scrollbar min/max can be limited by writing to the Doc Min, Doc Max properties.  I have attached a screenshot of the block diagram.  The constant value labeled "# rows visible-1" is set to the # of elements visble on the front panle minus 1, and keeps the array control from displayiong empty elements that would allow the user to edit.  Also, although the Page Size property is set to zero for the scorllbar, which should allow scrolling from Doc Min to Doc Max,  it does not accept this as a valid value, and instead is coerced to a value of 1.  I have submitted a SR on this as it may be a bug since the LV Help suggest that zero/negative values should be acceptable for the Page Size property.


I think this is the cleanest solution to the issue, although it would be best if the size of the array control could be fixed in size by setting a property item.  I will see about adding this as a suggestion.



0 Kudos
Message 7 of 10



You have not fixed the size of the array. You are only controlling the appearance of the control.  The control is not the array.  The array is the wire.  The control just allows the user to enter values.


While controlling the appearance probably has solved your immediate problem, be aware that LabVIEW does not support the concept of a fixed size array in general.



0 Kudos
Message 8 of 10

If the array is initialized to a specified number of elements (as in my example), and the user is prevented from adding elements to the array control, then the array will never be larger (or smaller) than the number of elements it is initialized to.  Of course, the developer could always change this in code by using build array, etc., but this was not my intention.


I imagine this all depends on the definition of "fixed".  And the immediate problem you refer to was my only issue at hand, nothing else, and it was solved.  


And actually, in LabVIEW FPGA applications, all arrays MUST be fixed in size and is a supported/required option.


0 Kudos
Message 9 of 10


  I like your solution, it works well if you always have more data (or exactly as much data) than needed to fill the visual space of the array container on the front panel.  However, in my case, the array container on the front panel must remain fixed in size (7 elements high) but sometimes there are fewer than 7 or more than 7 elements.  So I not only need to keep the scrollbar, but I also need to prevent labview from stuffing the free visual space with null elements when there are too few!

  I've solved this problem by building an XControl that has an array, a scrollbar, and a decoration that simulatesthe bounds of an array container. There is also a similar and "conventional" way to do it using property nodes and decorations.  The result is an array that allows you to have empty space in the visual container, and also prevents the user from seeing the null element at the end when scrolling down.  See this link if you're interested.


It seems kind of silly that we have to go through these circumlocutions to acomplish something that should be fairly simple, but there it is.

0 Kudos
Message 10 of 10