In a legacy VB6 application I have the following code:
Select Case lngItemID
'Other cases ommitted
Case menuIndexs.mnuClaimsThirdPartyDetails
Dim aobjReturn() As Object
Dim aobjData() As Object
' Additional code ommitted
End Select
Erase aobjReturn
Erase aobjData
Where are the variables aobjReturn & aobjData actually in scope?
This article: VB6 variable scope tutorial seems to indicate that the scope is local to the Sub. If this is correct, surely it could lead to issues with referencing variables that haven’t been ‘Dim’d yet?
They are scoped to the routine; if they are referenced before they are declared with
DimandOption Explicit(make declaration mandatory) is enabled then a “use of undeclared variable” compile time error occurs. IfOption Explicitis not set then a compile time ‘Variable declared more than once’ error is raised.