This article lists tips or tricks that become common wisdom once you've been using LabVIEW forever, but which newbies are sometimes uninformed of. Sometimes you discover something "new" that has never been mentioned anywhere and have never stumbled upon before. You wind up asking yourself, "How come I never knew this?"
Let's share our favorite insights here and we can use this article as starting point for introducing new users to some cool tips and tricks right away. This article should help the newcomer quickly become a masterful LabVIEW programmer!
Note: Only a few keyboard shortcuts are listed here in the tips and tricks. For a complete list go over to the LabVIEW keyboard shortcuts.
Uncategorized tips
Editor Note: Place new tips and tricks here if you can't decide or care about categorizing them. Someone else will find a place. If your tip deserves a dedicated section, go ahead.
String constant wrapping right while typing
When you drop a string constant, if you type text, all the text appears on a single line. If you type long enough, you start stretching out your autogrowing structure nodes and overlapping other parts of your diagram. You can type a carriage return, but that puts an extra character in your string. What most people do is stop typing, resize the string to the size they want and then go back to typing in the value. The trick is shift+Return. When you're typing in a string constant, the first shift+return will stop the string growing horizontally. As you type after that, the string will word wrap and add lines to the constant. Then if you do shift+return again, you'll turn on the vertical scroll bar. Now the string constant won't grow any further at all.
String control or constant
Drag and drop VI icon over string control to get the VI name into the control.
Tools Palette
- Press the <Shift> key and right-click to display a temporary version of the Tools palette at the location of the cursor.
- When automatic tool selection is disabled, you can use the <Tab> key to move through the most commonly used tools in the sequence they appear on the palette.
- To use another tool without clicking to disable automatic tool selection, click the tool you want to use. When you are finished, press the <Tab> key or click the Automatic Tool Selection button to enable automatic tool selection again.
- Hold the CTRL-key down when you have the painting tool selected and it changes to the get color tool. Good when you are matching colors in different controls or indicators. Hold the CTRL key down, click on the object you want to match in color, release the CTRL key and click on the object you want to color.
- If you have the autotool on, the mouse cursor changes to "the most needed tool on this region of the screen." Sometimes that means each tool gets only a small region of the screen. I hear people want to turn the autotool off when they try to move a boolean button -- they can get the operate tool and the text tool, but they can't find the very small region to get the pointer tool. Hit the control key. If you hold down the control key, it is defined to give you "the second most needed tool on this region of the screen."
- To temporarily switch to the Positioning tool when automatic tool selection is enabled and another tool is selected, press the <Shift> key.
- To temporarily switch to the Scrolling tool when automatic tool selection is enabled, move the cursor over any open space on the front panel or block diagram and press the <Shift-Ctrl> keys.
- If automatic tool selection is disabled, press the spacebar to switch to the next most useful tool on the Tools palette.
Multiple formats and text in a numeric indicator
It is a little known fact that you can have static text embedded in the contents of a numeric control or indicator. You can also specify more than one format string which results in multiple versions of the same number in the indicator. All of this magic is done using the advanced editing mode in the display format dialog of a numeric control or indicator. One great use-case for this is to display units to the right or left of the numeric (ex: 1.35 Volts).
To display percentage without explicit scaling, for example set the format to "%d %%" and the unit string to "cm/m". The controls stays unit-less but the displayed number is multiplied by 100 (100cm in 1 meter).
Icon editor
- Double click the font icon in the icon-editor. This brings up a dialog to set the font you want if you don't like the default.
- Double-clicking the "Selection Box" selects the entire icon. (+del key =A fast way to delete the Default Icon)
- Double-clicking the "Rectangle Box" puts a rectangle around the icon perimeter.
- Double-clicking the "Filled Rectangle Box" puts a rectangle around the icon perimeter and fills the inside.
- If you have entered text and before you select another tool use the cursor keys to move the text around pixel by pixel to make it center nicely etc.
- For icon editing, you can drag a picture file or another VI's icon over (with the arrow tool) and automatically update the icon picture.
- If you pick the font called: SMALL FONTS and use CAPS with size 8 then this looks great in the icon regardless of what you type.
- To create a smaller icon, make sure that all three areas (B&W, 16 color and 256 color) in the icon editor have your small icon. The actual icon border conforms to the largest of the three icon drawing areas.
- Anything in the clipboard (image, text, control) can be pasted into the icon editor and automatically sized to fit if you have a cut rectangle already set. Perfect for scaling things into place without doing it in an image editor. Not perfect, but very useful.
- Holding down Ctrl will switch to the colour selection tool, no matter what tool you've actually selected.
- Holding down Ctrl-Shift will switch to the colour picker, but when you click, the colour becomes the active background colour, not the foreground colour. This is very useful for replacing text on an icon that has a non-white background:
- Open the icon editor
- Ctrl-Shift-Click anywhere on the background colour
- Using the selction tool, select the text to be deleted and hit Delete (note that the background gets filled with the proper colour, not white)
- Select the text tool and type in your new text
- To copy an image to a VI icon, drag the image file and place it on the icon located in the upper right corner of the front panel or block diagram.
Wiring
- To cancel a wire you started, press the <Esc> key, right-click, or click the source terminal.
- To bend a wire while wiring, click to tack down the wire and move the cursor in a perpendicular direction. To tack down a wire and stop building it without connecting the wire, double-click.
- You can swap the inputs on most double input functions (comparison, numeric...) by holding <ctrl> down and hovering over the function. If both inputs are wired, you will see the arrow change to a sort of double loop and a click will swap the inputs.
- While routing a wire, press the space-bar to change the bend direction of the wire.
- With positioning tool:
- Single click on a wire: Highlights just that wire section
- Double click on a wire: Highlights wire up to a junction
- Triple click on a wire: Highlights the whole wire
- When you are moving or wiring to the edge of the screen, you can press the <Shift> key for a speed boost (10 pixels at a time instead of just 1)
- When inserting a two-input object (like AND or multiply) into an existing wire if you bias the mouse pointer just slightly below the wire before selecting "Insert -> (object)" then the object will be inserted with the incoming wire connected to the object's upper terminal. If you bias the mouse pointer just slightly above the wire before selecting "Insert -> (object)" then the object will be inserted with the incoming wire connected to the object's lower terminal.
- To automatically route an existing wire, right-click the wire and select Clean Up Wire from the shortcut menu.
- Press the <A> key after you start a wire to temporarily disable automatic wire routing and route a wire manually. Press the <A> key again to enable automatic wire routing for the wire. You also can temporarily disable automatic routing after you click to start or set a wire by holding down the mouse button while you wire to another terminal or set point and then releasing the mouse button.
- If automatic wire routing is disabled, you can switch the direction of a wire between horizontal and vertical by using the Wiring tool to click a terminal and pressing the spacebar. If automatic wire routing is enabled, you also can press the spacebar to switch the direction of a wire.If LabVIEW finds a route for the wire in the new direction, the wire switches to that direction.
- Toggle automatic wiring by pressing the spacebar while you drag an object onto the block diagram or move an object using the Positioning tool.
- To change the path of an existing wire without first deleting the wire, create the new wire path between the same terminals. LabVIEW deletes the previous wire path.
- To undo the last point where you set a wire, press the <Shift> key and click anywhere on the block diagram.
- When you have a broken wire between an array and a scalar, right-clicking on the wire conveniently shows "Insert Index Array" or "Insert Build Array".
- To add a meaningful name of the wire in the help window, right-click the wire and select 'Description'.
Case structure
Please take a look at the Case Structure page.
Error handling
- Case structures accept the error cluster directly as an input to the selector terminal. This automatically creates an error and no error case.
- The Select function accepts the error cluster data type. Error or No error are the two selections.
- The conditional terminal on While loops and For loops accept the error cluster data type. An error causes the loop to terminate. (Note, For loops can have a conditional terminal, as of LabVIEW 8.5, by right-clicking on them and selecting Conditional Terminal.)
- To look up error codes, right-click the status button inside an error cluster or the error cluster border and select Explain Error, or select Help»Explain Error from the shortcut menu.
- Positioning the cursor over the horizontal scroll bar and scrolling the mouse causes the display to scroll left and right.
- Shift+mouse scroll causes the scrolling to happen in large jumps.
- When you have a VI on a block diagram you can quickly jump to the diagram of the VI. Hold down the Ctrl key in Windows at the same time as you double-click the VI icon with your mouse.
- To temporarily switch to the Scrolling tool when automatic tool selection is enabled, move the cursor over any open space on the front panel or block diagram and press the <Shift-Ctrl> keys.
- To open the front panel of a subVI, double-click the subVI icon.
- To search for a specific primitive\subVI, select it in an open diagram and press <Ctrl-F>. The find dialog will be opened with that object as the search parameter.
- In the Search Results dialog box, to find the next search result, press the <Ctrl-G> keys. To find the previous search result, press the <Ctrl-Shift-G> keys.
- To scroll through Case, Sequence, or Event structure subdiagrams, move the cursor over the selector label and hold down the <Ctrl> key while moving the mouse wheel.
- To display an overview of the active front panel in edit mode or the active block diagram, display the Navigation window by selecting View»Navigation Window.
- To quickly split the screen into half front panel and half block diagram hit the <Ctrl-T> keys. (It may be convenient to disable this feature under Options -> Shortcuts since <Ctrl-T> is close to the commonly used shortcut of <Ctrl-R> for run)
Project environment
- You can arrange items on the Files page. Right-click a folder and select Arrange by»Name from the shortcut menu to arrange items in alphabetical order. Right-click a folder and select Arrange by»Type from the shortcut menu to arrange items by file type. Right-click a folder and select Arrange by»Path from the shortcut menu to arrange items by file path.
- Add a VI to a project by dragging and dropping it into a LabVIEW project library. When a VI is part of a project library, LabVIEW qualifies the VI name with the project library name to avoid cross-linking. A qualified name includes the filename and the qualified name of the owning project library filename. The qualified name changes without changing the path or filename.
- To quickly switch between application instances, right-click on the application instance name that appears in the application instance shortcut menu on the bottom left corner of the front panel and block diagram windows. Select the application instance (see image).
Call library function
Use the "Specify path on diagram" to determine if you can input the Library name or path on the block diagram. When you place a checkmark in this checkbox, path in and path out appear as input and output terminals on the connector pane for the node. When you place a checkmark in the checkbox, any library referenced in the Library name or path control will not be used.
Note: You can use the path in input to unload a previously referenced library from memory. Wire an empty or invalid path to the path in input to unload any library previously referenced by the node from memory.
Formula node
- Add comments to the text in a Formula Node by enclosing them inside a slash-asterisk pair (/*comment*/), or after a double-slash (//comment).
- Short scripts work well with the Formula Node because the Formula Node executes faster than the MathScript Node.
LabVIEW Classes
You can create a directory on disk named the same as the LabVIEW class to save the class library file, class member VIs, and class custom default probes. You can include the files that the class library owns in the directory. If you include files for more than one class library in the same directory, conflicts might occur if you try to include VIs of the same name in different class libraries. Naming conflicts can occur in the development process when you override dynamic member VIs.
Template VIs
You can add templates as subVIs to a template VI. To add a template as a subVI, open the VI template and drag the VI icon in the upper right corner of the front panel or block diagram window to the block diagram of the top-level template VI. When you create a VI from a template that contains template subVIs and save the VI, LabVIEW prompts you to save each template subVI as a VI.
- To increment or decrement a numeric control or constant, use the Labeling tool to place the cursor in the control and press the up or down arrow keys.
- To increment or decrement numeric controls faster, use the Operating or Labeling tools to place the cursor in the control and press the <Shift> key while clicking the increment or decrement buttons.
- For arrays
- While executing a VI: If you right click on an Array Index Display of a control, indicator or probe, you can select 'Show Last Element' to go to the last element of the array.
- In development mode: If you want to look at the last element of an array control or indicator, right click on the Index Display and select Advanced-->Show Last Element (there is no 'Advanced' menu for probes so it always works by just right clicking).
Graphs
- You can use an annotation instead of a cursor to highlight data points on the plot area.
- To increase the point size of data symbols on graphs and charts, increase the line width of the plot.
Debugging
- Enter single-step mode by clicking the Step Into or Step Over button on the block diagram toolbar. Move the cursor over the Step Into, Step Over, or Step Out button to view a tip strip that describes the next step if you click that button.
- Double-click the block diagram terminal to find the front panel object
- When you have selected Retain Wire Values and you place the cursor over a wire, a tip strip appears, that includes the value of the data in the wire.
- Use conditional custom probes to break your code on a specific condition.
- To pause the execution of a VI at any subVI, node, or wire, use the Breakpoint tool to click the object and run the VI.
- To temporarily stop the execution of a VI or to insert a probe, click the Pause button on the toolbar.
- To edit a VI set to run when opened, place it on the block diagram of a new, blank VI and double-click it.
- When a subVI is paused or suspended when called, click the Call list pull-down menu located on the block diagram toolbar of the subVI to list all the callers from the top-level VI down to the opened subVI. The Call list pull-down menu only appears on the block diagram toolbar of the subVI when the subVI is suspended.
- To easily get rid of all breakpoints in a hierarchy (the current VI and all subVIs), click on Edit >> Remove Breakpoints from Hierarchy. This is a great tool for removing all breakpoints after debugging a section of code.
Editing
- To make more space on the block diagram press Ctrl and drag.
- To duplicate objects, use the Positioning tool and press the <Ctrl> key as you drag the object.
- To create a constant, drag a front panel control to the block diagram. To create a control, drag a block diagram constant to the front panel.
- Select File»VI Properties and select Editor Options from the Category pull-down menu to change the style of the control or indicator LabVIEW creates when you right-click a terminal and select Create»Control or Create»Indicator from the shortcut menu. Select Tools»Options and select Front Panel from the Category list to change the style of the control or indicator LabVIEW creates in new VIs when you right-click a terminal and select Create»Control or Create»Indicator from the shortcut menu.
- To replace nodes, right-click the node and select Replace from the shortcut menu.
- Right-click the output tunnel and select Use Default If Unwired from the shortcut menu to use the default value for the tunnel data type for all unwired tunnels.
- To speed VI construction, right-click VI or function terminals and select Create»Constant, Control, or Indicator from the shortcut menu.
- To insert an object into an existing wire, right-click the wire and select Insert from the shortcut menu.
- To display a VI or function connector pane, right-click the node and select Visible Items»Terminals from the shortcut menu.
- To create a class-specific, type-specific control reference in LabVIEW without right clicking on a control reference and navigating through several menus. Simply drag or ctrl+drag a front panel control into a control Refnum to create a correspondingly typed reference.
Performance
- The block diagram usually requires the most memory. When you are not editing the block diagram, save the VI and close the block diagram to free space for other VIs. Saving and closing subVI front panels also frees memory.
- To use memory more efficiently, eliminate coercion dots at numeric terminals. <Control>-click the input value on the block diagram and select Representation from the shortcut menu to change the representation of the input value to the representation of the terminal.
- To reduce memory requirements and improve performance slightly for a VI, disable the debugging tools. Select File»VI Properties, select Execution from the top pull-down menu, and remove the checkmark from the Allow debugging checkbox.
- To monitor the performance of a VI, select Tools»Profile»Performance and Memory to display the Profile Performance and Memory window. Click the Start button, then run the VI.
- To improve the overall performance of VIs, avoid displaying and manipulating large arrays and strings.
- To increase the speed at which a VI runs, avoid unnecessary computations in looping structures.
- Use local variables and global variables only when necessary. Overuse can cause slower execution, inefficient memory usage, or race conditions.
- Break large top-level VIs into small subVIs to reduce the amount of memory an application consumes.
- To further increase the speed a VI executes, reduce the number of I/O calls you make by reducing the amount of data you acquire or by acquiring the data with fewer calls.
- To increase the speed at which a VI runs, reduce the time spent updating front panel controls and indicators.
- To increase the speed at which a VI runs, avoid using autoscaling on graphs and charts if it is not needed.
- To increase the speed at which a VI runs, update graphs and charts several points at a time, not one point at a time.
- To increase the speed at which a VI runs, force less important parallel tasks to wait using the Wait (ms) function so crucial tasks have more processor time.
- Use the Control Value:Get [Variant], Control Value:Set [Variant], and Control Value:Get All [Variant] methods to get and set control values to or from the LabVIEW variant data type. You do not have to flatten data or specify a type descriptor when you use these methods.
- When converting variant data to or from LabVIEW data, avoid performing further operations on a wire branch of the original source data. If you continue to use the variant data after the initial conversion, LabVIEW must make a copy of the data, which can slow performance.
Calling or creating a subVI
- You can place an open VI on the block diagram of another open VI. Use the Positioning tool to click the icon in the upper right corner of the front panel or block diagram of the VI you want to use as a subVI, and drag it to the block diagram of the other VI.
- Note: If you hold down the Shift key while doing so, any control attached to the connector pane whose value is not default will automatically have its input wired with a constant.
- Drag a VI or control from the file system to a LabVIEW block diagram to create a subVI call to that VI.
- Always leave some extra open (unused) connections on the connector pane of a subVI. You'll save yourself a lot of time and pain on that inevitable day when you need to add some more I/O to a VI you swore you'd never need to expand. You have to choose a new connector pane, possibly rearrange your control/indicator connections, and start relinking (and possibly rewiring) every instance where you call the subVI.
- Drag VIs, controls, and global variables from the VI Hierarchy window onto the front panel and block diagram.
- To create subVIs from a portion of the block diagram, select the portion and then select Edit»Create SubVI.
- To display a subVI as an expandable node, right-click the subVI and select View As Icon from the shortcut menu to remove the checkmark. Resize the subVI to better display input and output terminals.
- LabVIEW users frequently need to open a VI reference for a VI that is next to the current file on disk. A VI name can be passed directly into the Open VI Reference function, which will locate the VI in the current VI’s directory.
- A subVI can be called dynamically simply by right clicking on that VI and selecting Call Setup.
File path control or constant
- To avoid typing out the path, you can drag a file from the desktop (or file explorer) and drop it into the file path constant or control.
- To list multiple file types in a file dialog box using the File Dialog function or Open/Create/Replace File VI, wire a string constant or control to the pattern terminal and use semicolons to separate the patterns, for example fx*.bin;*.c.
Resizing Objects
- To resize an object as you add it to the front panel, click to place the object, hold the mouse button down, and drag the mouse until the dashed border outlines the object size you want. Note that this must be done in one continuous motion without releasing the mouse button until the sizing is complete. (Hold the <Ctrl> key down as you drop it and will resize from the center, hold the <Shift> key and it will resize proportional to its original size.)
- If the alignment grid is enabled, you can resize an object only in units the size of the grid. You can temporarily disable the alignment grid by pressing the <G> key.
- Even after you have placed a new control/indicator on the front panel, to keep an object proportional to its original size as you resize it, press the <Shift> key as you resize.
- To resize a selected object to a specific size in pixels, use the Positioning tool to move the cursor over a resizing handle and click and hold the mouse button. A tip strip that lists the current size of the object in pixels appears outside the bottom border of the front panel or block diagram window. As you resize the object, use the tip strip to change the size to a specific size in pixels.
Moving objects
- To restrict an objects direction of movement horizontally or vertically, press the <Shift> key while you move the object.
- To move selected objects one pixel, use the appropriate arrow key. To move objects several pixels, use the <Shift> key and the appropriate arrow key.
- If you work with a grid on your BD (or FP) then the following may prove handy to know. Do you get frustrated when you want to move things around but in doing so all your lovely straight wires on the BD become crooked again? Well with a single keystroke, this bothersome behavior can be avoided.
- Simply hold down the <SHIFT> key before clicking on an object or a selection and move with confidence ! Your movements will be constrained to Left/Right or Up/Down.
Match Regular Expression
- To anchor a match at the beginning and end of a string, use a caret (^) as the first character in a pattern and a dollar sign ($) as the last character of a pattern. For example, ^dog$ matches dog in dog but not dog catcher or the dog. Note that anchoring the match at the beginning and end of the string requires the whole string to match.
- Use back references to refer to previous partial matches in a regular expression. To specify a back reference, use \1 to refer to the first partial match, \2 to refer to the second, and so on. For example (cat | dog) \1 matches cat cat or dog dog but not cat dog or dog cat.
Documentation
- Label For Loops using a For Each syntax that reflects the array elements that you are iterating over.
- To make labels transparent, use the Coloring tool and right-click the T in the color picker.
- To display the optional terminals of a connector pane and to display the full path to a VI in the Context Help window, click the Show Optional Terminals and Full Path button in the Context Help window.
- Press the <Ctrl-Shift-L> keys to lock the Context Help window so its contents do not change when you move the cursor over different front panel or block diagram objects.
- To link from a VI to an HTML file or a compiled help file, select File»VI Properties, select Documentation from the pull-down menu, and enter a Help path and Help tag.
- To quickly create Web pages that document the VIs that you create, select File»Print and select the HTML file option on the Destination page.
- To place a free label on the front panel or block diagram when automatic tool selection is enabled, double-click any open space.
- The dialog label in the controls palette is very special. You can use this label to label wires on the diagram instead of using your own colors. What makes the dialog label different from the default label is that the background color inherits the color properties of whatever object or background you place it on. Normally, this label is used on front panels because it allows you to label dialog frames properly. Windows XP color themes contain various shades and textures which cannot be represented by a single color. However a nice bonus is the benefit of labeling wires without having to play with the colors. You must select this label from the controls palette to drop it since it's not available on the functions palette. Note in newer version of LabVIEW, the dialog label is called the system label.
- If you place dialog labels over wires and then use the VI Analyser to inspect your VI's, the Block Diagram, Style test "Wires Under Objects" will report a fail for this situation by default. You can avoid this fail and still ruin the test by unchecking the <Include Decorations> in the VI Analyser Test Configuration page.
Hardware IO
- Set VISA Aliases in Measurement & Automation Explorer to make VISA resource names easier to remember.
- Drag a name from Measurement & Automation Explorer to a LabVIEW front panel to create a name control automatically.
- VISA Open is optional. If you wire a VISA name control directly to any VISA function, a VISA session opens automatically when you first use the function.
Palettes
- You can view the Controls and Functions palettes as categories, icons, text, icons with text, or a tree. To change the palette format for all palettes, select Tools»Options and select Controls/Functions Palettes from the Category list. To change only the palette format for the current palette, click the View button on the Controls or Functions palette toolbar and select a format from the View This Palette As shortcut menu.
- Right-click any block diagram object and select Source Palette from the shortcut menu to access similar objects from a subpalette, where Source is the name of the subpalette that contains the block diagram object. If you right-click a node terminal, two subpalette shortcut menu items might appear. The first is the source palette of the node, and the second is the most commonly used source palette of the terminal data type. Right-click a block diagram object and select Replace»Source Palette from the shortcut menu to replace the block diagram object with a similar object from the subpalette that contains the block diagram object. Right-click a wire and select Insert»Source Palette from the shortcut menu to insert an object from the most commonly used source palette.
- If you like to have a fixed place where your palettes are you can pin them with the pinpen. However if you want to keep the 'floating' behaviour that the palettes revert to their default state they were in after selecting a function use the right mouse button to click on the palette submenu item.
- To insert a new, empty subpalette on the Controls or Functions palette or to link to an existing palette, select Tools»Advanced»Edit Palette Set, right-click the palette, and select Insert»Subpalette from the shortcut menu.
- Right-clicking in the diagram brings up a temporary palette, when you pick something on the palette, it puts the object on your cursor to drop.
- If you ctrl-right click instead and do the same thing, instead of dropping the object, it opens the panel of the VI (if the object you picked off the palette is a subVI).
Menus
- To add external VIs and LLBs to the LabVIEW Tools menu, place them in the labview\project directory and restart LabVIEW.
- To add a menu mnemonic insert an '_' (underscore) before the letter you want to be triggered.
XControls
There is a way to create so called "pull-right" properties for XControls. Change the localized long name of the property to include the nesting. For Example: If you have a property called My New Nested Property 1 and you want the menu to appear like Mike->My New Nested Property 1, set the Localized Long Name to Mike:My New Nested Property 1. Colon is used as the separator.
- You can create line separators by replacing the Localized Long Name completely with a hyphen "-". Of course, this means you lose access to the property since now it's not selectable. You would probably create dummy properties to support this.
Closing References
- The Close Reference function accepts a 1D array of references. It's polymorphic.
VI Usage
- Close without saving, if you want to close a VI without a prompt to save it use the following code snippet:
No comments:
Post a Comment