When I execute the code below, the value of the "element" variable at the last line equals to 1 instead of 3. Can somebody tell me why?
The variable "element" at the last line would equals to 3 if I don't use the preserve keyword with the redim statement.
Sub test()
On Error Resume Next
Dim array1() As String
Dim element As Integer
element = 0
ReDim Preserve array1(element + 1, 1)
element = UBound(array1, 1)
element = element + 1
ReDim Preserve array1(element, 1)
element = UBound(array1, 1)
element = element + 1
ReDim Preserve array1(element, 1)
element = UBound(array1, 1)
End Sub
Bookmarks