PDA

View Full Version : Array Constant



jlefebvre
01-12-2006, 08:23 AM
is it possible to declare a constant array publically?

i have a list of things that won't change that i want to use throughout the code, but can't seem to:

Public Const KeyArray(1 to 10) = Array("item",....)

thoughts?

austenr
01-12-2006, 09:18 AM
' Private and Public must be used at the module level.
Private MyArray3() As Single
Public MyArray4() As Double

Killian
01-12-2006, 09:26 AM
Hi and welcome to VBAX :hi:

Unfortunately, the answer to your first question is 'no' :(
A constant has be declared as being a particular data type (string, integer, long, etc) rather than an expression o rdata structure.

Another limitation of VB is you can't have an array of constants, you need to list your constants separately.

Bob Phillips
01-12-2006, 09:56 AM
You can get close enough with a bit of work


Public Const sKeyArray = "item1,item2,item3"
Public KeyArray

Sub testit()
Dim i As Long
KeyArray = Split(sKeyArray, ",")
For i = LBound(KeyArray) To UBound(KeyArray)
Debug.Print KeyArray(i)
Next i
End Sub