# Alphabet Iterator

Hi everyone,

I would like to name columns of a Listbox with letters of the alphabet. Is there a way to automate/iterate this with a loop?

[code]A | B | C | D | … | AA | AB | …

For i As Integer = 0 To Listbox1.ColumnCount
Next[/code]

Would be nice to use the new Xojo Framework.

Thanks!

Use `Chr(val)` instead of `LETTER`

Val is the ASCII value (41 ?) for the A capital letter.

BTW: a bit more complex if you want AA, AB 'till ZZZZZ

LETTER was just to show you where the output should be The idea from Emile is the correct one. Have a look at an ASCII tabe (for instance http://asciichart.com). From A to Z are the numbers 65 to 90. Chr(65) = A and so on. Then you need to do an integer division of 26 to get the number of letters. Can you now get the algorithm?

You could also use a constant with each of the letters in it and then use the modulus operator for the position and integer divisor \ to get the count.

This will only fill the 26 first Headings. I don’t know enough about using Mod().

[code]Const Alphabet As Text = “ABCDEFGHIJKLMNOPQRSTXYZ”

Dim i As Integer

For Each c As Text In Alphabet.Characters

If i = 26 Then Exit

i = i + 1

Next[/code]

So it was \$41 ;- Eventually:

a. How will you add a Column ?

b. For the Row #, you may add a second Listbox with only one column and fill the Column in a Loop, and synch the two Listbox scroll.
If you add or remove a Row, you can populate the Listbox.

But I may be wrong.

@Emile Schwarz : The users adds various columns. So I don’t know the count of columns.

But you have to make the Column Header Strings consistent ( A  Z, AA  ZZ).

That’s the solution [h]GetNameFromNumber(num As Integer) As String[/h]

[code]Dim numeric As Integer = num Mod 26
Dim letter As String = Chr(65 + numeric)
Dim num= As Integer = num / 26

If num = 0 Then
Return GetNameFromNumber(num2 - 1) + letter
Else
Return letter
End If[/code]