I have a code structure something like this:
For row = 1 To numRows Dim arrayIndex As Integer = 0 For column As Integer = startColumn To endColumn ' whatever code arrayIndex = arrayIndex + 1 Next Next Dim arrayIndex As Integer = 0 For column As Integer = startColumn To endColumn ' whatever code arrayIndex = arrayIndex + 1 Next
Not really a code, so I donβt need refactoring suggestions, but my problem is with this code I get a compiler error for the first Dim arrayIndex As Integer = 0 - βVariableβ arrayIndex 'hides the variable in the enclosing block. "As far as I can tell , arrayIndex is local to the first for loop and should not exist by the time the second loop is reached. If I try to change the second declaration of arrayIndex to arrayIndex = 0 , I get the error "The name" arrayIndex "is not declared", as I expected. So it can be seen or not? Is this related to the Dim keyword? Any suggestions on that How to get around this, differing from the name of the second index variable something else?
source share