PDA

View Full Version : Create a consecutive character array?



jayzeus
07-14-2008, 05:30 PM
I've been trying to create an array that consists of consecutive double characters (AA, AB, AC, etc), from AA to AZ.

I think I've got a logic right, I'm starting with two arrays

A1 = Array("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")
A2 = Array("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")

Then I was trying to run it through two for loops, and spit it out into a third containter array.

For some reason, maybe it's because how for loops are executed in VBA, I either keep running out of indexes or I'm not doing anything at all.

Any ideas on how to accomplish that? Is there an easier way to do that?

Here's what I have so far:

For m = 0 To 24
For n = 0 To 24
A3(c) = A1(m) + A2(n)
c = c + 1
Next n
Next m
Except that, in this case, I lose the last chars of the set. If I change the indexes to 25 it says that the subscript is out of range. What gives?

jayzeus
07-14-2008, 06:48 PM
I'm such a dumbass. I calculated my A3 (my container array) size as 625, but apparently I can't multiply 26 by 26.... I knew it was something simple!

mikerickson
07-14-2008, 07:11 PM
Would this function be of use?
Function doubleAlpha(index As Long) As String
If -1 < index And index < 676 Then
doubleAlpha = Chr(65 + Int(index / 26)) & Chr(65 + index - 26 * Int(index / 26))
End If
End Function

doubleApha(i) = A3(i)

Bob Phillips
07-15-2008, 01:17 AM
ReDim A3(0 To (UBound(A1) - LBound(A1) + 1) * (UBound(A2) - LBound(A2) + 1) - 1)
For m = LBound(A1) To UBound(A1)
For n = LBound(A2) To UBound(A2)
A3(c) = A1(m) + A2(n)
c = c + 1
Next n
Next m