|
-
Feb 7th, 2000, 03:58 AM
#1
Thread Starter
New Member
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
-
Feb 7th, 2000, 10:15 PM
#2
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|