D
Dale Atkin
I've been a big fan of explicit variable declaration ever since many years
ago when I spent nearly a whole day trying to track down a bug, that was the
result of a simple 'typo'. Ever since, I've made sure "Option Explicit" was
on in every program I write, and I've never looked back.
I've noticed however that in certain circumstances, the compiler doesn't
seem to mind inferring the data type of some variables.
For example, I would have expected that the following code would generate an
error:
Private Function DoSomething() As String
For i = 0 To 10000
Next
Return 0
End Function
But it doesn't. It seems that the For loop is somehow an exception to the
'explicit' variable declaration rule, and I'm not sure why, or what other
situations this same 'exception' might apply in, and its making me a bit
nervous.
Dale
ago when I spent nearly a whole day trying to track down a bug, that was the
result of a simple 'typo'. Ever since, I've made sure "Option Explicit" was
on in every program I write, and I've never looked back.
I've noticed however that in certain circumstances, the compiler doesn't
seem to mind inferring the data type of some variables.
For example, I would have expected that the following code would generate an
error:
Private Function DoSomething() As String
For i = 0 To 10000
Next
Return 0
End Function
But it doesn't. It seems that the For loop is somehow an exception to the
'explicit' variable declaration rule, and I'm not sure why, or what other
situations this same 'exception' might apply in, and its making me a bit
nervous.
Dale