For years I've been telling people that they shouldn't write any VB or VBScript
code without first specifying Option Explicit. Well, times change and I no
longer use Option Explicit. These days it's Option Strict.
In VB.NET, just declaring your variables isn't enough anymore. In order
for your code to perform at its best, you really should include
type information when you declare your variables:
Dim intLoopVar As Integer Dim strFirstName As String = "John"
In order to require you to assign types to all your variables, use the Option Strict
compiler option. If you're using VB.NET, you can use Option Strict
anywhere you can use Option Explicit. If you want to use it in an ASP.NET web form,
simply add the Strict attribute to the Page directive:
<%@ PageLanguage="VB"Strict="True"%>
Once you add the Strict attribute, any attempt to run the page without
specifying the types of your variables will result in a compilation error
something like this:
Compiler Error Message: BC30209: Option Strict On requires all variable declarations to have an 'As' clause.
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.