VB6 局部变量作用域
在旧版 VB6 应用程序中,我有以下代码:
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
变量 aobjReturn
& 在哪里? aobjData
实际上在范围内吗?
这篇文章: VB6 变量作用域教程 似乎表明作用域是 Sub 的本地作用域。如果这是正确的,那么肯定会导致引用尚未“变暗”的变量出现问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们的范围仅限于日常工作;如果它们在使用
Dim
声明之前被引用,并且启用了Option Explicit
(强制声明),则“使用未声明的变量”编译出现时间错误。如果未设置 Option Explicit ,则会引发编译时“变量声明多次”错误。They are scoped to the routine; if they are referenced before they are declared with
Dim
andOption Explicit
(make declaration mandatory) is enabled then a "use of undeclared variable" compile time error occurs. IfOption Explicit
is not set then a compile time 'Variable declared more than once' error is raised.