I'm trying to write a counter that uses the alphabet as the count like this:
[ul]
[li]A[/li]
[li]B[/li]
...
[li]Y[/li]
[li]Z[/li]
[li]AA[/li]
[li]AB[/li]
...
[li]AZ[/li]
[li]BA[/li]
[li]BB[/li]
....
[li]ZY[/li]
[li]ZZ[/li]
[li]AAA[/li]
[li]AAB[/li]
[/ul]
Here's my current (incomplete) code. It's a recursive function where you pass in a counter value and it's converted to a letter via Chr(). It's close, but at the transition from AY, AZ, BA, BB it begins to have problems and miscalculates either AZ or BA depending on adjusting the increment.
Take a look & if you've already got one written, that'll be great!
[ul]
[li]A[/li]
[li]B[/li]
...
[li]Y[/li]
[li]Z[/li]
[li]AA[/li]
[li]AB[/li]
...
[li]AZ[/li]
[li]BA[/li]
[li]BB[/li]
....
[li]ZY[/li]
[li]ZZ[/li]
[li]AAA[/li]
[li]AAB[/li]
[/ul]
Here's my current (incomplete) code. It's a recursive function where you pass in a counter value and it's converted to a letter via Chr(). It's close, but at the transition from AY, AZ, BA, BB it begins to have problems and miscalculates either AZ or BA depending on adjusting the increment.
Take a look & if you've already got one written, that'll be great!
Code:
[blue]Dim[/blue] x
[blue]For[/blue] x = 1 [blue]to[/blue] 100
[green]'debug.print sAlphaCounter(x)[/green]
response.write(sAlphaCounter(x) & "</br>")
[blue]Next[/blue]
[blue]Function[/blue] sAlphaCounter([blue]ByVal[/blue] iCountValue)
[blue]Dim[/blue] sRetVal
sRetVal = ""
[blue]If[/blue] iCountValue > 26 [blue]Then[/blue]
sRetVal = sAlphaCounter(Int(iCountValue/26))
[blue]If[/blue] 26 [blue]Mod[/blue] iCountValue = 0 [blue]Then[/blue]
iCountValue = iCountValue + 1
[blue]Else[/blue]
iCountValue = iCountValue - (Int(iCountValue/26) * 26)
[blue]End If
End If[/blue]
iCountValue = iCountValue + 64
sRetVal = sRetVal & Chr(iCountValue)
sAlphaCounter = sRetVal
[blue]End Function[/blue]