More About Strings


We introduced strings in Chapter 4, "LabView Foundations"a string is simply a collection of ASCII characters.[1] Often, you may use strings for more than simple text messages. For example, in instrument control, you pass numeric data as character strings. You then convert these strings to numbers to process the data. Storing numeric data to disk can also use strings; in many of the file I/O VIs, LabVIEW first converts numeric values to string data before it saves them to a file.

[1] At the time of this writing, the current release of LabVIEW, 8.0, does not support Unicode, although it's a feature that may appear soon.

Choose Your Own Display Type

String controls and indicators have several options you might find useful. For example, they can display and accept characters that are normally nondisplayable, such as backspaces, carriage returns, and tabs. If you choose "\" Codes Display (instead of Normal Display) from a string's pop-up menu, nondisplayable characters appear as a backslash (\) followed by the hexadecimal value of the ASCII character.

Table 9.1 shows the meaning of the various "\" codes.

Table 9.1. LabVIEW "\" Codes

Code

LabVIEW Implementation

\00 \FF

Hexadecimal value of an 8-bit character; alphabetical characters must be uppercase

\b

Backspace (ASCII BS, equivalent to \08)

\f

Formfeed (ASCII FF, equivalent to \0C)

\n

New line (ASCII LF, equivalent to \0A)

\r

Return (ASCII CR, equivalent to \0D)

\t

Tab (ASCII HT, equivalent to \09)

\s

Space (equivalent to \20)

\\

Backslash (ASCII \, equivalent to \5C)


You should know that some commonly used non-printable characters, such as space (0x20), tab (0x09), carriage return (0x0D), new line (0x0A), and so on are not shown in "\" codes display with a hexadecimal value following the backslash (\). Instead these common non-printable characters have a single lowercase letter that represents the non-printable character. For example, you will never see "\20" (0x20 is the hexadecimal value of the space character), only "\s" (the "\" code of the space character). In fact, if you type "\20" into a string that is configured for "\" codes display, the "\20" will immediately be converted to "\s."

You must use uppercase letters for hexadecimal characters and lowercase letters for the special characters, such as formfeed and backspace. LabVIEW interprets the sequence \BFare as hex BF followed by the word "are," whereas LabVIEW interprets \bFare and \bfare as a backspace followed by the words "Fare" and "fare." In the sequence \Bfare, \B is not the backspace code, and \Bf is not a valid hex code. In a case like this, when a backslash is followed by only part of a valid hex character, LabVIEW assumes a zero follows the backslash, so LabVIEW interprets \B as hex 0B. Any time a backslash is not followed by a valid character code, LabVIEW ignores the backslash character.


This string shows the Backslash code for the New Line character in Normal Display mode (see Figure 9.1).

Figure 9.1. String control in Normal Display mode


After switching to "\" Codes Display mode, the string shows the spaces entered by the user (see Figure 9.2).

Figure 9.2. String control in '\' Codes Display mode


Don't worrythe data in the string does not change when the display mode is toggled; only the display of certain characters changes. '\' Codes Display mode is very useful for debugging programs and for specifying nondisplayable characters required by instruments, the serial port, and other devices.

Strings also have a Password Display option, which sets the string control or indicator to display a "*" for every character entered into it, so that no one can see what you type. Although the front panel shows only a stream of "****," the block diagram reads the actual data in the string. Obviously, this display can be useful if you need to programmatically password-protect all or part of your VIs. Figures 9.3 and 9.4 show the front panel and block diagram of a VI that passes data from a string control in Password Display mode to a string indicator in Normal Display mode. Note that the string data remains unchanged, regardless of the display mode.

Figure 9.3. String control in Password Display mode (left) and string indicator in Normal Display mode (right) displaying the same string data


Figure 9.4. Block diagram showing that the string control passes its data, unchanged, to the string indicator


If you want to see your string as hexadecimal characters instead of alphanumeric characters, use the Hex Display option.

Figure 9.5 shows the same string displayed in each of the four display options: Normal, "\", Password, and Hex.

Figure 9.5. The same string data displayed in each of the four display modes


Single Line Strings

When a string control is used as a text entry box on a user interface VI, it is often desirable to limit the string to a single line. In this scenario, when a user presses <enter> or <return>, it signifies that she is finished entering text. If you desire this single line behavior, select the Limit to Single Line option from a string's pop-up menu. If this option is not enabled, then the string is not limited to a single line: hitting <return> causes the cursor to jump to a new line to let you type more.

Updating While You Type

Normally, string controls don't change their value on their terminal in the block diagram until you finish typing and either hit <enter>, click outside the string box, or click on the "" button on the VI toolbar to indicate the string entry is complete. Most of the time you will want this behavior, because you dont want your block diagram code to evaluate an incomplete string before a user is finished typing.

If you do want the value to be updated as you type (just like a knob, for example), pop up on the string control and select Update Value While Typing.

The Scrollbar

If you choose the Visible Items>>Scrollbar option from the string pop-up Visible Items>> submenu, a vertical scrollbar appears on the string control or indicator. You can use this option to minimize the space taken up on the front panel by string controls that contain a large amount of text. Note that this option will be grayed out unless you've increased the size of your string enough for a scrollbar to fit.

Tables

A table is a special structure that displays a two-dimensional (2D) array of strings. You can find it in the Lists & Table subpalette of the Controls palette. A table in all its glory is shown in Figure 9.6.

Figure 9.6. Table control


Tables have row and column headings that you can show or hide; the headings are separated from the data space by a thin open border space. You can enter text headings using the Labeling tool or Operating tool (like everything else). You can also update or read headings using property nodes, which you've heard so much about and will learn how to use soon enough.

Like an array index display, a table index display indicates which cell is visible at the upper-left corner of the table.

For a good example of a table and how to use it, open and run Building Tables.vi, located in EVERYONE\CH09.

Listboxes

There are two kinds of listboxes in LabVIEW: Listbox and Multi-column Listbox, from the List & Table palette.

A listbox control looks similar to a table, but it behaves very differently at run-time. During edit mode, you can type any text into a listbox just like you would a table. When you run the VI, the listbox acts as a "multiple choice" menu where you can click on any row to highlight it and select it.

A listbox's value is the row number that is selected (or an array of row numbers, if the listbox is configured to allow multiple row selection via the Selection Mode>>0 or More Items or Selection Mode>>1 or More Items pop-up menu options). This is very different from a table control, whose value is a 2D array of strings. For a listbox, you can programmatically change the item strings that appear in the control by writing to the Item Names property (using a property node, which you will learn about in Chapter 13, "Advanced LabVIEW Structures and Functions").

Figure 9.7 shows a multi-column listbox.

Figure 9.7. Multi-column listbox


Listboxes are useful when you want to present data (either single-column or multiple-columns) to a user, but you just want them to choose one or more of the items.

If text does not fit in a cell of a table or listbox, a tip strip with the full text appears when you run the VI and place the cursor of the Operating tool over the cell.

Pop up on a single-column listbox and select Multi-line Input to allow cell entries to contain multiple lines.

You can select Autosize Row Height from the pop-up menu of a single-column listbox to configure how the rows change height for font changes and multiple-line text entries.

To allow users to edit the cell string values of a listbox, at run-time, pop up on a listbox and select Editable Cells.


For a simple example of how a listbox works, see Listbox Example.vi in EVERYONE\CH09.




LabVIEW for Everyone. Graphical Programming Made Easy and Fun
LabVIEW for Everyone: Graphical Programming Made Easy and Fun (3rd Edition)
ISBN: 0131856723
EAN: 2147483647
Year: 2006
Pages: 294

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net