Count from A to AA

Hi all,

Is it possible to count from A,B,…,Z,AA,AB,AC,…ZZ,AAA,AAB… etc?

I thought of using ASCII but my algo doesn’t seem to perform the way i want it to be, especially during the changing part from Z to AA and ZZ to AAA.

I know an alternative to this would be in numbers, but i think i would want to use this kinda of counting method.

Any suggestions?

Thanx in advance.

Regards,

Hengshi

Subject: Count from A to AA

this is nothing but excel spreadsheet col count

take the number

Subtract 26 from the number,

if the answer is > 0 Add A to a string

Repeat the process till answer is less than 26 and

set the appropriate alphabet, append to string

Subject: RE: Count from A to AA

here is the code.hope this helps.x=your current alphabet sequence

y=length of the current alphabet sequence

a=0

If(Right(x,1)=“Z”) Then

		For i=1 To y

			If(Mid(x,y-i+1,1)="Z") Then

				a=a+1

				Mid(x,y-i+1,1)="A"

			Else

				Exit For 

			End If

		Next

		If(a=y) Then

			x="A"&x

		Else

			Mid(x,y-a,1)=Chr(Asc(Mid(x,y-a,1))+1)

		End If

	Else

		Mid(x,y,1)=Chr(Asc(Mid(x,y,1))+1)

	End If

Subject: Count from A to AA

I’ve used hexidecimal for counting, but it’s not often that is needed. I think the only advantages are to hide to the enduser what number it represents, or (in the case I mentioned) count higher with fewer digits… FF = 255 and FFF = 4095

What purpose do you have for counting, anything specific?

Subject: RE: Count from A to AA

Hi Stan,

I am required to use that to count the number of times the document have been edited. I not sure why I must use that kinda counting style but as you know, it is not my call. haha

But i do not understand your algo, what do you mean by using hexadecimal? Coz i thought of using hexa also, but the problem will be during the transition from Z to AA and from ZZ to AAA.

Thanx

Best

Hengshi

Subject: RE: Count from A to AA

The difficulty with a system which goes fro A to Z, then AA to ZZ, then AAA to ZZZ is that you are giving AAA a different value than for AA or A. In hexadecimal system you go from 0 to F, then from 10 (Note! not 00, like in you AA case) to FF, then from 100 to FFF.

If you would go from A to Z, then BA to ZZ, then BAA to ZZZ, it would be a simple icosekaihexadecimal system, where A means 0 in decimal system (see naming conventions: http://mathforum.org/dr.math/faq/faq.polygon.names.html) but digits going from A to Z, and not from 0 to Q (like in the normal hexadecimal system)

Anyway, you need a dectoalpha() and alphatodec() function, which converts a decimal number to a alphanumeric sequence, and vice versa:

Function alphatodec(s)

a=Asc("A")-1

c=1

n=0	

For i=Len(s) To 1 Step -1

	n=n+((Asc(Mid(s,i,1))-a)*c)

	c=c*26

Next

alphatodec=n

End Function

Function dectoalpha(n)

a=Asc("A")-1

m=n

While m>=1

	p=m Mod 26

	If p=0 Then p=26

	m=m-p

	t=Chr(a+p)+t

	m=m/26

Wend

dectoalpha=t

End Function