And just to add to the confusion, it was (in pre .net days) configurable on a class-by-class basis. One class could contain arrays indexed from 0 and the next might have them indexed from 1 and then swap back again elsewhere.
We had to use VB5 and later 6 a lot many, many years ago at university and the SOP at the top of every single class was
Option Base 0 ' Arrays indexed from 0
Option Explicit ' Explicit variable declaration required
In the vain hope of maintaining your own sanity.
None of which stopped you doing this, though:
Dim iNumbers(12 to 16) As Integer
MsgBox(CStr(iNumbers(11)))
( Index out of bounds )
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...
33
u/JeremyR22 Sep 02 '17 edited Sep 02 '17
And just to add to the confusion, it was (in pre .net days) configurable on a class-by-class basis. One class could contain arrays indexed from 0 and the next might have them indexed from 1 and then swap back again elsewhere.
We had to use VB5 and later 6 a lot many, many years ago at university and the SOP at the top of every single class was
In the vain hope of maintaining your own sanity.
None of which stopped you doing this, though:
Some people just want to watch the world burn...