Wrap It Up!An array is a collection of ordered data elements of the same type. In LabVIEW, arrays can be of any data type, except chart, graph, or another array. You must create an array using a two-step process: first, place an array shell (Modern>>Array, Matrix & Cluster subpalette of the Controls palette) in the window, and then add the desired control, indicator, or constant to the shell. LabVIEW offers many functions to help you manipulate arrays, such as Build Array and Index Array, in the Programming>>Array subpalette of the Functions palette. Most often, you will use these array functions to work with only 1D arrays; however, these functions are smart and will work similarly with multidimensional arrays (although sometimes you need to resize them first). Both the For Loop and the While Loop can accumulate arrays at their borders using auto-indexing, a useful feature for creating and processing arrays. Remember that by default, LabVIEW enables indexing in For Loops and disables indexing for While Loops. Polymorphism is a fancy name for the ability of a function to adjust to inputs of different-sized data. We talked about polymorphic capabilities of arithmetic functions; however, many other functions are also polymorphic. Clusters also group data, but unlike arrays, they will accept data of different types. You must create them in a two-step process: first, place a cluster shell (Modern>>Array, Matrix & Cluster subpalette of the Controls palette) on the front panel or block diagram (for an array constant), and then add the desired controls, indicators, or constants to the shell. Keep in mind that objects inside a cluster must be all controls or all indicators. You cannot combine both controls and indicators within one cluster. Clusters are useful for reducing the number of wires or terminals associated with a VI. For example, if a VI has many front panel controls and indicators that you need to associate with terminals, it is easier to group them as a cluster and have only one terminal. The Unbundle function (Programming>>Cluster & Variant palette) splits a cluster into each of its individual components. Unbundle By Name works similarly to Unbundle, but accesses elements by their label. You can access as many or as few elements as you like using Unbundle By Name, while you have access to the whole cluster using Unbundle (and have to worry about cluster order). The Bundle function (Programming>>Cluster palette) assembles individual components into a single cluster or replaces an element in a cluster. Bundle By Name can't assemble clusters, but it can replace individual elements in a cluster without accessing the entire cluster. In addition, with Bundle By Name, you don't have to worry about cluster order or correct Bundle function size. Just make sure all cluster elements have names when using Bundle By Name and Unbundle By Name! The error cluster is a special datatype in LabVIEW (a cluster consisting of a status Boolean, code I32, and source string) that is used for propagating information about errors that occur during the execution of LabVIEW code. Many of LabVIEW's functions and VIs have error in and error out terminals. These are almost always found (if present on the function or VI) on the lower-left and lower-right terminals of the connector pane (respectively). Chain the VIs with error in and error out together for enforcing dataflow and ensuring that errors propagate through your application. When building subVIs, it is important to conform to the standard expectations with respect to error handling and propagation. Put functional code inside an Error Case Structure to not execute that code when an error flows into your VI. Merge errors coming from VIs executing in parallel. Don't pop up error dialogs from subVIs. Use error dialogs in your main application only when you cannot handle them in a suitable fashion. |