I don't believe its possible to declare a constant array using VBA (or
VB for that matter), though anyone please correct me if that isn't the case. One suggestion, though, that might make your code more maintainable if you are using a large number of constant elements would be to maintain a table of constant values, and load your array from the table. The easiest way I can think of to get your sample values into a multi-dimensional array would be to first load a one-dimensional array, and use that to load the multi-dimensional array (looking for a short cut if one is out there).
The code below prints the following to the debug window:
One-Dimensional Array
A1
A2
A3
B1
B2
B3
C1
C2
C3
Two-Dimensional Array
Col 1 Col 2 Col 3
Row 0 A1 A2 A3
Row 1 B1 B2 B3
Row 2 C1 C2 C3
Also included is code to load the 1-dimensional array from a text file if you wanted to store your contants there.
*******Code*************************************** ****************
Dim m_arrConstants(2, 2) As String
Sub LoadOneDimensionalArray()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim arrConstants() As String
Dim intCount As Integer
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "tblConstants", cnn, adOpenStatic, adLockPessimistic
intCount = 0
Debug.Print "One-Dimensional Array" & vbCrLf
With rst
Do Until .EOF
ReDim Preserve arrConstants(intCount)
arrConstants(intCount) = rst!ConstDesc
Debug.Print arrConstants(intCount)
intCount = intCount + 1
.MoveNext
Loop
.Close
End With
Set rst = Nothing
Call LoadArray(arrConstants())
Call PrintMultidimensionalArray
End Sub
'**LOAD MULTIDIMENSIONAL ARRAY FROM 1-DIMENSIONAL ARRAY
Sub LoadArray(a() As String)
Dim row As Integer, col As Integer
Dim intCount As Integer
intCount = 0
For row = LBound(m_arrConstants) To UBound(m_arrConstants)
For col = LBound(m_arrConstants, 2) To UBound(m_arrConstants, 2)
m_arrConstants(row, col) = a(intCount)
intCount = intCount + 1
Next col
Next row
End Sub
'**PRINT MULTIDIMENTIONAL ARRAY
Sub PrintMultidimensionalArray()
Dim row As Integer, col As Integer
Dim temp As String
Debug.Print vbCrLf & "Two-Dimensional Array" & vbCrLf
temp = " Col 1 Col 2 Col 3"
Debug.Print Space$(9) & temp
For row = LBound(m_arrConstants) To UBound(m_arrConstants)
temp = "Row " & row & " "
For col = LBound(m_arrConstants, 2) To UBound(m_arrConstants, 2)
temp = temp & Space$(4) & m_arrConstants(row, col) & " "
Next col
Debug.Print temp
Next row
End Sub
'**LOAD 1-DIMENSIONAL ARRAY FROM A TEXT FILE
Sub LoadFile(strSourceFile As String)
Dim arrConstants()
Dim intFileDesc As Integer 'File descriptor for output file
Dim itCount As Integer
intCount = 0
intFileDesc = FreeFile
Open strSourceFile For Input As #intFileDesc
Do While Not EOF(intFileDesc)
Line Input #intFileDesc, strTextLine 'Read line into buffer
ReDim Preserve arrConstants(intCount)
arrConstants(intCount) = strTextLine
Debug.Print arrConstants(intCount)
intCount = intCount + 1
Loop
Close #intFileDesc
End Sub