Example Code

Finding and Highlighting or Coloring a Word in a String Control Using 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

This example demonstrates how to search, find, highlight, and color characters or words in a string control. An event structure monitors the front panel controls buttons.

Description 

When you press the Highlight Next Word button, the VI searches for a space in the string control to determine when a word starts and ends. The VI highlights the word that occurs before the space. The shift register stores the position of the last highlighted word.

 

When you press the Color Words button, the VI searches for the text you specifiy and colors all instances of that string with the color you specify.

 

The Searching Algorithm SubVI uses the Match Pattern function to find an instance of the string in the Text to Search textbox. The top level VI uses the Searching Algorithm VI in a While Loop to build the location of each matching pattern into an array. Finally, the top level VI uses an indexed for loop to read one value from the array at a time and  change those values using a property node before displaying the  resulting text in the Highlighted Text indicator.

Requirements

LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Run the VI
  2. Press "Highlight Next Word" to highlight the next word
  3. Type a search term in "Text to Find"
  4. Select a "Highlight Color"
  5. Press "Color Words" to search for the search term and color the corresponding words

Additional Information or References

 

Front Panel

frontpanel.PNG

 

Block Diagram

blockdiagram.PNG

 

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ben Sisney
FlexRIO V&V Engineer
National Instruments
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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

Comments
ShogunOrta
Member
Member
on

This was GREAT!!!!!! Exactly what I needed. Great Job!