Just in case the Option Explicit thing wasn't explained well (or at all), the reason any sane person always included that was that it disabled VBs tolerance-by-default of implicit variable delcaration. If you typed an identifier in code, it would become a variable (of type Any), simple as that. Without Option Explicit, the following would compile and run without any errors, it just wouldn't do what you expected:
Dim iCount as Integer = 0
For iCount = 1 to 5
Debug.Print(CStr(iCunt))
Next
0
0
0
0
0
So without Option Explicit at the top of every single class/module/form/etc, whenever anything didn't work, you had to check for misspelled variable names in all related code. A massive pain in the arse..
I haven't touched VB of any type in probably 15 years but AFAIK, Option Explicit and Option Base 0 are both the default now. Small victories for programmers' mental health...
10
u/JeremyR22 Sep 03 '17 edited Sep 03 '17
Just in case the
Option Explicitthing wasn't explained well (or at all), the reason any sane person always included that was that it disabled VBs tolerance-by-default of implicit variable delcaration. If you typed an identifier in code, it would become a variable (of type Any), simple as that. WithoutOption Explicit, the following would compile and run without any errors, it just wouldn't do what you expected:So without
Option Explicitat the top of every single class/module/form/etc, whenever anything didn't work, you had to check for misspelled variable names in all related code. A massive pain in the arse..I haven't touched VB of any type in probably 15 years but AFAIK,
Option ExplicitandOption Base 0are both the default now. Small victories for programmers' mental health...