Example Code

Usability: Programmatically Return Line of Text when User Double-Clicks a given Line in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

Code that shows how we can determine which text was double clicked on a string control.

 

Description

If you have ever needed determine what line of text a user has selected (by double-clicking) such that you can do certain tasks or processes, here is a piece of code to do just that. For example, you may want to give the user more information, more options, definitions, links to other documentation with respect to the text he has selected. The first step is determining what text has been selected.

 

We start by generating an array of the starting location of each line. An Event Structure is used to determine if the user has double-clicked within a text box. From that, we get the location of the text that was selected. Final we parse through the existing array that defines the start and end position of each line to see if our selected text is located after the start of the first line and before the end of the first line. If so, we know the text is found in the first line and we return the whole first line of text, else we ignore the first line, and check the next line, so on and so forth.

 

In the end, we will end up iterating through the entire textbox to find the line. This is a great piece of code for most lengths of textboxes. If your text box gets quite large, and the For Loop is starting to delay your front panel updates you can:
1. Move the loop to another loop and use Producer/Consumer Events design pattern to handle the code more efficiently.
2. Use a different search technique such as binary search.

 

Requirements

LabVIEW 2012 or compatible

 

Steps to Implement or Execute Code
1. Run the VI.
2. Double-click on any text from the string control and see it displayed on the text indicator.
3. Finish the execution with the Stop button.

 

Additional Information or References

 Capture.PNG


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

--Michelle

National Instruments

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