Iteration

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

I am looking for a way to iterate from A to Z.
something like the For/Next loop, but with letters. the iteration
should start from specified letter and continue n times. If Z letter is
reached, the next should be AA, AB, AC and so on.

something like:

dim cStartLetter As char = P

dim i,j as integer
j=5
for i = 0 to j
'code to retrun the letter which is i positions from cStartLetter
position in alphabet
' P is 18th letter, so first iteration should return Q, next R and
so on
' if Z is reached the next should be AA. If AZ is reached the next
should be AAA.
next

sorry for the bad english
thanks in advance
 
Hi Nikolay,

The piece of the puzzle you are missing is CHR$(n) (it may be just CHR now).
Whereby when n=65 then result is 'A', 66='B'

Therefore,

result = CHR$(n)

HTH, Phil
 
Nikolay Petrov said:
I am looking for a way to iterate from A to Z.
something like the For/Next loop, but with letters. the iteration
should start from specified letter and continue n times. If Z letter is
reached, the next should be AA, AB, AC and so on.

\\\
For c As Integer = AscW("A") To AscW("Z")
MsgBox(ChrW(c))
Next c
///
 
Phill by 'n' I meaned 'x' number of times

If the first letter is 'P' and 'n' is 3 the result should be 'S',
because it is 3 letters after 'P' in alphabetical order.
And if the 'n' is big enough, so the result would be bigger than 'Z',
then a leading letter should be added, like 'Y' and 'n'=6q the reslut
should be 'AE'. And so on. If the rezult reaches 'AZ' the algorithm
should continue at 'Bx' until 'BZ', and so on, and on.
 
Back
Top