From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Convert Number to Corresponding Letter 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

Download All

Overview

This example is written for an application in which needs to convert a number into its corresponding letter

 

Description

This example is written for an application in which needs to convert a number into its corresponding letter.  For example, I need 1=A, 2=B, ..., 26=Z, 27=AA, ..., 52=ZZ, 53=AAA, etc. This example will return the corresponding letter for any positive integer number.  This application may be useful when performing such tasks as referencing Microsoft Excel column names (A, B, C, ...) via ActiveX.

 

Requirements

  • LabVIEW 2012(or compatible)

 
Steps to Implement or Execute Code

  1.  Run the vi.

 

Additional Information or References

Front panel

FP.JPG

 

VI Snippet

BD.png

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

Patrick W.
Applications Engineer
National Instruments

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

Comments
1984
Active Participant
Active Participant
on

27 gives AA which is correct, but 28 gives BB which is incorrect as the next column in excel is AB

Nicolas_Socomec
Member
Member
on

You can design a quite simple VI working from A to ZZZ (which makes some 18928 rows) based on the indexing of an array containing an empty string and the 26 letters ! See the snippet attached for example !

Mine goes 0=A, 1=B,... 25=Z, 26=AA, 27=AB,... 701=ZZ, 702=AAA, etc... but you can make your own based on your needs !
I use it for Excel ActiveX in Labview, quite useful
Excel column name.png

crossrulz
Knight of NI Knight of NI
Knight of NI
on

Nicolas_Socomec wrote:

Mine goes 0=A, 1=B,... 25=Z, 26=AA, 27=AB,... 701=ZZ, 702=AAA, etc... but you can make your own based on your needs !                   

Found a bug in your code.  1377 is AZZ, but then 1378 is AZA (should be BAA).  From there, you are off by 26.

Here is a more generic version (does not care how many letters it takes)

ExcelColumnName.png


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Nicolas_Socomec
Member
Member
on

My bad, I had no use of so many columns so I did not test these values !

Thank you for your answer ! Maybe this post should be edited to mention your code or at least not refer to Excel column names ?