473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Incrementing Letters

Im not finding anything similar in the Posts so correct me if Im wrong...

Im real new to programing in Access (Been a while since I programed in anything). The question I have is.. How do you make letters increment?

It may sound weird but, I need to create unique numbers based on day and year. That part I can do. The last two Digits in the Number are two letters though ... AA through ZZ and I cant figure out how to get those to increment through all their values. i.e. AA,AB,AC,AD....ZY,ZZ.

Any ideas how to do this?
Oct 4 '07 #1
9 6496
Jim Doherty
897 Expert 512MB
Im not finding anything similar in the Posts so correct me if Im wrong...

Im real new to programing in Access (Been a while since I programed in anything). The question I have is.. How do you make letters increment?

It may sound weird but, I need to create unique numbers based on day and year. That part I can do. The last two Digits in the Number are two letters though ... AA through ZZ and I cant figure out how to get those to increment through all their values. i.e. AA,AB,AC,AD....ZY,ZZ.

Any ideas how to do this?
Unless someone else grasps this I cannot see in what context you are wanting to use it yes I understand the concept of AA then AB then AC for 26 repetitions on the A ........then onto B for 26 repetitions till we exhaust that then onto C and so on but in what real practical sense you wish to use it then.... No

If you merely want to have a viewable list of the combinations to work with then create a ONE field table add the letters of the alphabet to it and add this table to a query TWICE. do not join anything between the two tables simply run the query you will have a list of every possible combination. This is known in SQL parlance as a CROSS join every combination of everything so to speak

I'm not convinced I've helped you

Regards

Jim
Oct 5 '07 #2
JConsulting
603 Expert 512MB
Im not finding anything similar in the Posts so correct me if Im wrong...

Im real new to programing in Access (Been a while since I programed in anything). The question I have is.. How do you make letters increment?

It may sound weird but, I need to create unique numbers based on day and year. That part I can do. The last two Digits in the Number are two letters though ... AA through ZZ and I cant figure out how to get those to increment through all their values. i.e. AA,AB,AC,AD....ZY,ZZ.

Any ideas how to do this?

This will probably work...but I'm curious what happens when you run out of alphabet

Expand|Select|Wrap|Line Numbers
  1. Function IncrementAlpha(strIn As String) As String
  2. 'Pass this function your two letter string 
  3. 'Example    myNewString = IncrementAlpha("ab")
  4. 'will return "ac"
  5.  
  6. Dim sAlphaBet As String
  7. Dim sFirstLetter As String
  8. Dim sSecondLetter As String
  9. Dim X As Variant
  10. Dim I As Long
  11. sFirstLetter = Left(strIn, 1)
  12. sSecondLetter = Right(strIn, 1)
  13. sAlphaBet = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
  14. X = Split(sAlphaBet, ",")
  15.  
  16. If sSecondLetter = "z" Then
  17.     'loop to get next first letter
  18.     For I = I To UBound(X) - 1
  19.         If X(I) = sFirstLetter Then
  20.             sFirstLetter = X(I + 1)
  21.             sSecondLetter = "a"
  22.             Exit For
  23.         End If
  24.     Next I
  25. Else
  26.     'loop to get the next second letter
  27.     For I = 0 To UBound(X) - 1
  28.         If X(I) = sSecondLetter Then
  29.             sSecondLetter = X(I + 1)
  30.             sFirstLetter = sFirstLetter
  31.             Exit For
  32.         End If
  33.     Next I
  34. End If
  35. IncrementAlpha = sFirstLetter & sSecondLetter
  36. End Function
  37.  
J
Oct 5 '07 #3
ADezii
8,834 Expert 8TB
Im not finding anything similar in the Posts so correct me if Im wrong...

Im real new to programing in Access (Been a while since I programed in anything). The question I have is.. How do you make letters increment?

It may sound weird but, I need to create unique numbers based on day and year. That part I can do. The last two Digits in the Number are two letters though ... AA through ZZ and I cant figure out how to get those to increment through all their values. i.e. AA,AB,AC,AD....ZY,ZZ.

Any ideas how to do this?
Pass this Function 2-Letters and it will do the incrementing for you:
Expand|Select|Wrap|Line Numbers
  1. Public Function fIncrementLetters(strLastLetters As String)
  2. 'Check for exactly 2 Letters - (Upper or Lower Case)
  3. If Len(strLastLetters) <> 2 Then Exit Function
  4. If Asc(UCase$(Left$(strLastLetters, 1))) < 65 Or Asc(UCase$(Left$(strLastLetters, 1))) > 90 Then Exit Function
  5. If Asc(UCase$(Right$(strLastLetters, 1))) < 65 Or Asc(UCase$(Right$(strLastLetters, 1))) > 90 Then Exit Function
  6.  
  7. If UCase$(Right$(strLastLetters, 1)) <> "Z" Then
  8.   fIncrementLetters = UCase$(Left$(strLastLetters, 1)) & Chr$(Asc(UCase$(Right$(strLastLetters, 1))) + 1)
  9. Else
  10.   fIncrementLetters = Chr$(Asc(UCase$(Left$(strLastLetters, 1))) + 1) & "A"
  11. End If
  12. End Function
SAMPLE OUTPUT:
fIncrementLetters("lz") ==> "MA"
fIncrementLetters("AA") ==> "AB"
fIncrementLetters("Qg") ==> "QH"
fIncrementLetters("ZZ") ==> "[A"
...etc.

NOTE: It does not check for the last possible Letter Combination, namely ZZ as clearly indicated in the last Sample Output. I'll leave this up to you but if you are stuck, please let me know.
Oct 5 '07 #4
JConsulting
603 Expert 512MB
Pass this Function 2-Letters and it will do the incrementing for you:
Expand|Select|Wrap|Line Numbers
  1. Public Function fIncrementLetters(strLastLetters As String)
  2. 'Check for exactly 2 Letters - (Upper or Lower Case)
  3. If Len(strLastLetters) <> 2 Then Exit Function
  4. If Asc(UCase$(Left$(strLastLetters, 1))) < 65 Or Asc(UCase$(Left$(strLastLetters, 1))) > 90 Then Exit Function
  5. If Asc(UCase$(Right$(strLastLetters, 1))) < 65 Or Asc(UCase$(Right$(strLastLetters, 1))) > 90 Then Exit Function
  6.  
  7. If UCase$(Right$(strLastLetters, 1)) <> "Z" Then
  8.   fIncrementLetters = UCase$(Left$(strLastLetters, 1)) & Chr$(Asc(UCase$(Right$(strLastLetters, 1))) + 1)
  9. Else
  10.   fIncrementLetters = Chr$(Asc(UCase$(Left$(strLastLetters, 1))) + 1) & "A"
  11. End If
  12. End Function
SAMPLE OUTPUT:
fIncrementLetters("lz") ==> "MA"
fIncrementLetters("AA") ==> "AB"
fIncrementLetters("Qg") ==> "QH"
fIncrementLetters("ZZ") ==> "[A"
...etc.

NOTE: It does not check for the last possible Letter Combination, namely ZZ as clearly indicated in the last Sample Output. I'll leave this up to you but if you are stuck, please let me know.
Mine is prettier Dez :o)
Oct 5 '07 #5
Thanks to both of you for your help. I'll try them both and see which one works better :)

As for checking for the last possible combination "ZZ", If I ever get 676 items in in one day....My job has gotten way too complex and I won't get them all checked in anyway, then it will be the next day and the counter starts over. :) So I don't think ZZ will ever get used
Oct 5 '07 #6
ADezii
8,834 Expert 8TB
Mine is prettier Dez :o)
Never said my code was pretty, only functional. (LOL).
Oct 5 '07 #7
They both work... So Thanks to all... When it is ZZ and tries to increment it gets an error... But again no big deal cause thats way more than Ill ever need :)
Oct 30 '07 #8
ADezii
8,834 Expert 8TB
They both work... So Thanks to all... When it is ZZ and tries to increment it gets an error... But again no big deal cause thats way more than Ill ever need :)
No provision was made for this contingency, as indicated by the notation on Post #4. You can simpy exit the Function if this condition exists via:
Expand|Select|Wrap|Line Numbers
  1. If UCase$(strLastLetters) = "ZZ" Then Exit Function
Oct 30 '07 #9
FishVal
2,653 Expert 2GB
Hi, everyone.

Just another approach.
The value may be stored in table as number and converted to base 26 numeration system (digits A-Z) number when needed.

Expand|Select|Wrap|Line Numbers
  1. Public Function GetAZNumber(ByVal intInput As Integer) As String
  2.  
  3.     GetAZNumber = Chr(Int(intInput / 26) + Asc("A")) & _
  4.         Chr(intInput Mod 26 + Asc("A"))
  5.  
  6. End Function
  7.  
Oct 31 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: trickydicky | last post by:
Does anyone know of an easy way to increment a string by one letter at a time? What I want to be able to do is set a variable with the value "A" and then be able to use a For loop to make it...
2
by: Edward K. Ream | last post by:
From the documentation for the string module at: C:\Python23\Doc\Python-Docs-2.3.1\lib\module-string.html letters: The concatenation of the strings lowercase and uppercase described below....
11
by: John Velman | last post by:
I've used perl for a lot of 'throw away' scripts; I like Python better in principle, from reading about it, but it was always easier to just use perl rather than learn python. Now I'm writing a...
9
by: Michael | last post by:
Hi, I've got a string s, and i want to shift all the letters up by one, eg a->b, b->c ........ z->a In c++ i can do this quite simply with if(C == 'z') C='a'; else C++; but i can't work out...
3
by: Mothra | last post by:
Here's what I'm trying to do (kill off old Unix logins): --------------------- $i=0; while (<$who>) { chomp($_); my @line = split(/\s+/, $_); # Split it into an array next unless ($line...
2
by: brian | last post by:
Hi, before coming to .NET, I utilized regular expressions mostly in JScript / JavaScript and also in my favorite text editor: TextPad (www.textpad.com) I don't know about JScript/JavaScript, but...
10
by: Antanas | last post by:
The problem is that when AddID is used multiple times in the same select statement, it returns the same value in all places. How could I force function AddID to increment OBJECTID sequence? Here...
8
by: JD via AccessMonster.com | last post by:
I am trying to create a field where the primary key field will produce JDP- 001; where the three letters come from the first name, middle intial and last name of my table. I want to auto increment...
9
by: subramanian100in | last post by:
The following portion is from c-faq.com - comp.lang.c FAQ list · Question 6.13 int a1 = {0, 1, 2}; int a2 = {{3, 4, 5}, {6, 7, 8}}; int *ip; /* pointer to int */ int (*ap); /* pointer to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.