As others have pointed out, VB doesn't have constant arrays. What you can do,
though, is have a function that returns a safe copy of an array (or
collection, or any other thing) each time it's called, so even if code that
uses it changes the content, it will never affect what the next caller gets
when they call the same function.
Of course, if you copy an object (such as a collection), you have to make sure
you really cloned it, and did not just pass another reference to the same
object.
Public Function MyArrayValues() As String()
Static sblnInitialized As Boolean
Static sastrResult(1 to 5) As String
If Not sblnInitialized Then
sastrResult(1) = "A"
sastrResult(2) = "B"
sastrResult(3) = "C"
sastrResult(4) = "D"
sastrResult(5) = "E"
sblnInitialized = True
End If
MyArrayValues = sastrResult
End Function
Public Sub TestArray()
Dim varItem As Variant
For Each varItem In MyArrayValues
Debug.Print varItem
Next
End Sub
On Sun, 8 May 2005 13:50:46 +1200, "xtra" <wi**********@hottermail.com> wrote:
Hi Folk
Is it possible to declare a constant array
e.g.
dim i() as string
i(1) = ...
i(2) = ...
seems to work but the following does not
const i(1) = ....
const i(2) = .....
It is nice to put them into an array, because that means you can loop
through it.
Cheers
Nicolas