Example Code

Determine Clicked Array Element Index in LabVIEW

Code and Documents

Attachment

If you've ever researched methods for determining which element of an array the user clicked on in LabVIEW, you have probably noticed that LabVIEW provides a method for converting pixel coordinates to a row-column pair for tables, but no such method exists for arrays.

The Determine Clicked Array Element Index VI converts pixel coordinates to row-column pairs for 1D or 2D arrays - enabling you to easily determine which element of an array the users of your application clicked on.

Many of the currently available methods for  determining which element of an array the user clicked on in LabVIEW have some shortcomings or limitations, so I decided to see if I could develop a method for accomplishing this that would meet two primary criteria:

  1. It has to be easy for LabVIEW users of all skill levels to implement.
  2. It has to return the correct index under all of the following conditions:
    • The array of interest is a 1D or 2D array
    • The array of interest is displayed horizontally or vertically
    • The array of interest label, caption, scrollbars or index display are visible or not
    • The array of interest has an element gap displayed
    • The array of interest elements are physically large or small
    • The user has scrolled the visible portion of the array of interest using either the index controls or the scrollbars

The Determine Clicked Array Element Index VI enables you to easily determine which element of an array the users of your application clicked on.

The  Determine Clicked Array Element Index VI distribution includes a fully-documented and functional example VI that demonstrates how to use the Determine Clicked Array Element Index VI.

blue-starburst-sm_Download.png

and create an interface that is similar to the

glyph selector in the NI Icon Editor in an instant!

Glyph Selector Screenshot.png



Run the included example VI to see how you can use the Determine Clicked Array Element Index VI in your own applications.

Readme file for Determine Clicked Array Element Index VI

Description
The Determine Clicked Array Element Index VI takes the coordinates of click input and determines the index of the array element that the user clicked on.

NOTE: Proper operation of the Determine Clicked Array Element Index VI requires that a caption has been created for the array of interest by following the numbered steps below:

  1. Right click on the array of interest and select Visible Items >> Caption (The item should be checked)
  2. Right click on the array of interest and select Visible Items >> Caption (The item should be un-checked)
  3. Right click on the array of interest and select Visible Items >> Label (The item should be checked)
  4. Save the VI

Application Software


LabVIEW 2010 or later.

Driver Software


None.

Extracting the files


The Determine Clicked Array Element Index VI is supplied as a zip archive containing all required items.

Additional Information


Additional information related to the use and operation of the Determine Clicked Array Element Index VI may be accessed via:

  • The block diagrams of all included VIs
  • The documentation within all included VIs

Developed by

Mark Ridgley

Mark.Ridgley_LabVIEW.Developer@comcast.net

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

Comments
Tournifreak
Member
Member
on

Fab piece of work! Many thanks.
It's crazy that LabVIEW doesn't support this function natively. Not a problem any more though 🙂

Jon

Kyle203
Member
Member
on

Thanks for posting this.  However, I can't get it to run since on both downloads, it looks like the vi "Determine Clicked Array Element Index - Determine Array and Scrollbar Properties.vi" is missing.  Maybe I'm missing something?

Kyle

Mark.Ridgley
Member Member
Member
on

Hello,

I downloaded both the LabVIEW 2010 and 2011 versions, extracted them and found the Determine Array and Scrollbar Properties.vi at the following path:

..Distribution\Determine Clicked Array Element Index 201x\_Subs.

Please ensure that you have the latest latest downloads as indicated by the "File Added..." portion of the download filename. Give it another try and let me know if that solves the issue.

Thanks,

Mark Ridgley

Kyle203
Member
Member
on

Hi Mark,

I found the issue.  It turned out that the directory where I extracted the files into already had a long name and that combined with some of the long file names in the distribution caused a few of the files to clip off at the end, including the extensions.  I extracted to the C:\ level and it worked fine.  Thanks!

Kyle

Willy2a
Member
Member
on

It doesn't seem to work with LabVIEW 2012. I have checked and quadruple checked that the array has a caption (and a label). Even the array elements have captions - but I still get an error telling me to add a caption when I click the array. Is there an updated version for 2012, or is there some other issue?

-Marcus

Mark.Ridgley
Member Member
Member
on

Hi Marcus,

Thanks for downloading this code. I'm sorry to hear that you are having trouble with it.

I did a few tests to see if I could recreate what you are seeing. I used LabVIEW 2012 to open the LabVIEW 2011 version of the usage example VI that is included in the distribution. Everything loaded fine and the VI showed that it needed to be saved (as expected). I closed the VI and selected Save All when prompted. I re-opened the usage example VI, ran it and everything worked as expected.

Next, I built a new VI from scratch following the instructions in the block diagram of the usage example VI and everything worked as expected again.

I'm unable to duplicate the issue that you have described. Would you be able to send me a copy of the VI that you are having trouble with so that I can continue looking into this? If so, you can send the VI to the email address that you'll find in the VI description of the usage example VI.

I hope to hear from you soon.

Mark Ridgley

sagardoshi
Member
Member
on

Hi Mark,

Thank you so much for sharing.

-Sagar

DanishAhmad
Member
Member
on

Amazing,

Thank you so much Smiley Happy

-Danish

RVines
Member
Member
on

Thanks Mark! I adapted to work with right click shortcut menu cmds!

johnvoyager
Member
Member
on

That's beautiful !! Heart

 

 

X.
Trusted Enthusiast
Trusted Enthusiast
on

This needs updating for Silver and NXG styles (or any array control with modified border sizes) as the hardcoded values only work with Modern controls (and possibly Classic ones).

Contributors