Visual Basic 中 for 循环计数器的范围

问题描述 投票:0回答:1

考虑以下因素

dim nofTries as integer
For nofTires=1 to 5
 if(condition) exit for...
next 

由于拼写错误,循环计数器与声明的变量不同。然而,尽管设置了“选项显式”,但没有给出编译器警告或错误,这就像:

    dim nofTries as integer
For nofTires as integer=1 to 5
 if(condition) exit for...
next 

有没有解释为什么编译器自行假定类型而不是给出错误?

vb.net for-loop scope
1个回答
0
投票

这与 OPTION INFER 处于 ON 状态有关。将其关闭,就会出现所需的编译器错误。对我来说,误解的根源在于这个选项在 VBA 中并不存在,而且默认情况下它似乎是打开的,而关闭似乎更合理。

© www.soinside.com 2019 - 2024. All rights reserved.