I'm trying to understand arrays more thoroughly. Can someone please explain to me why this does not compile:
Public Sub Test()
Dim Names As String
Names = Array("Brian", "Steve", "Andrea")
Debug.Print Names(2) 'Compile error: Expected array
End Sub
and why this compiles but does not run:
Public Sub Test()
Dim Names() As String
Names = Array("Brian", "Steve", "Andrea") 'Run-time error '13': Type mismatch
Debug.Print Names(2)
End Sub
but this works, even though I didn't add () (unless declaring it as type Variant makes it an array?):
Public Sub Test()
Dim Names As Variant
Names = Array("Brian", "Steve", "Andrea")
Debug.Print Names(2)
End Sub
and so does this, as expected:
Public Sub Test()
Dim Names() As Variant
Names = Array("Brian", "Steve", "Andrea")
Debug.Print Names(2)
End Sub
Variantcan very well hold a pointer to an array. That makesVariant()pretty much redundant.