I'm having trouble understanding when brackets are/aren't required when declaring arrays of String and Variant types.
- This works as expected (declaring Pieces WITHOUT brackets, as Variant):
Dim str
str = "The quick fox"
Dim Pieces As Variant
Pieces = Split(str)
MsgBox(Pieces(1))
OUTPUT: quick
- This doesn't work (declaring Pieces WITH brackets, as Variant):
Dim str
str = "The quick fox"
Dim Pieces() As Variant
Pieces = Split(str)
MsgBox(Pieces(1))
"Type mismatch"
- This works (declaring Pieces WITH brackets, as String):
Dim str
str = "The quick fox"
Dim Pieces() As String
Pieces = Split(str)
MsgBox(Pieces(1))
OUTPUT: quick
- This doesn't work (declaring Pieces WITHOUT brackets, as String):
Dim str
str = "The quick fox"
Dim Pieces As String
Pieces = Split(str)
MsgBox(Pieces(1))
Won't compile "expected array"
I can understand 4. not working. But I can't understand the reasons for the Variant versions (1. and 2.) not working in the same manner and how a dynamic string array (3.) works without ReDim being used?