Results 1 to 2 of 2

Thread: Help! Need to get the letter set

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Ports, VA, US
    Posts
    1

    Post

    I am creating an application that will generate a letter set based on a specified number, where 2 = a, 27 = z, 28 = aa, 53 = az, so forth and so on, up to at least zz, but possibly up to 8-digits (i.e. azzzzzzzz-zzzzzzzz).

    What I would like to do is use a function that will allow me to input the number that corresponds to the letter set and have it return the corresponding letter set. This function will probably be recursive, and rely on a mathematical equation. I have worked with it a bit, but cannot seem to come up an equation that will work 100%.

    Here are the functions I am working with (original code from http://www.delphi.com/ab-visualbasic...s/?msg=988.3), but it only works up to zz, and has a problem calculating y and z (doesn't return y or z, but ? or @ respectively).

    Public Function Letter(num As Integer) As String Letter = Chr(num Mod 26 + 63) End Function

    Public Function Letters(num As Integer) As String If Int(num / 26) > 1 Then Letters = Letters(Int(num + 26 / 26)) & Letter(num) Else Letters = Letter(num) End If End Function

    Inputting the number 678 (e.g. Letters(678)) should return string "za".

    If you are able to help, you can send an email to me at [email protected]

    Thanks, Greg

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124

    Post

    Try this code. Make sure you change the Integer data types to Long.
    Code:
    Public Function Letter(ByVal num As Long) As String
        Letter = Chr(num Mod 26 + 65)
    End Function
    
    
    Public Function Letters(ByVal num As Long) As String
        num = num - 2
        If num > 25 Then
            Letters = Letters(Int((num + 26) / 26)) & Letter(num)
        Else
            Letters = Letter(num)
        End If
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width