I want to use a dynamic array containing arbitrary number of strings. The array is filled by if ... then
logic instead of a loop. I keep getting Subscript out of range
error:
Dim Files() As String
If True Then
ReDim Preserve Files(UBound(Files) + 1) ' Throws "Subscript out of range" error
Files(UBound(Files)) = "foo.pdf"
End If
If True Then
ReDim Preserve Files(UBound(Files) + 1)
Files(UBound(Files)) = "bar.txt"
End If
If True Then
ReDim Preserve Files(UBound(Files) + 1)
Files(UBound(Files)) = "baz.jpg"
End If
I have a function declared like this:
Function SendFiles(Files() As String)
I want to get rid of this error without using variants if possible. I can rewrite the code but I cannot use a loop.