Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB6 Local variable scope

Tags:

scope

vb6

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?

like image 617
TK. Avatar asked Jun 03 '26 02:06

TK.


1 Answers

They are scoped to the routine; if they are referenced before they are declared with Dim and Option Explicit (make declaration mandatory) is enabled then a "use of undeclared variable" compile time error occurs. If Option Explicit is not set then a compile time 'Variable declared more than once' error is raised.

like image 165
Alex K. Avatar answered Jun 06 '26 06:06

Alex K.