Rubberduck icon indicating copy to clipboard operation
Rubberduck copied to clipboard

unexpected "Variable is used but not assigned" on array after ReDim

Open interservices opened this issue 2 years ago • 0 comments

Version 2.5.2.5906 OS: Microsoft Windows NT 10.0.22000.0, x64 Host Product: Microsoft Office x64 Host Version: 16.0.15225.20288 Host Executable: EXCEL.EXE


I get two unexpected "Variable is used but not assigned" errors in this code:

Sub TEST()
    Dim i, arr
    ReDim arr(2)
    arr(0) = Array("aaa", "bbbb")
    arr(1) = Array("ccc", "dddd")
    arr(2) = Array("eee", "ffff")
    For i = LBound(arr) To UBound(arr) ' I get two "Variable 'arr' is used but not assigned." here
        '...
    Next
End Sub

I don't get the errors if I declare the array as fixed size without ReDim.

interservices avatar Jun 27 '22 15:06 interservices