Tutorial - Using Option Strict in ASP DotNet
When used, the Option Strict statement must appear before any other
code.
Visual Basic .NET generally allows implicit conversions of any
data type to any other data type. Data loss can occur when the value
of one data type is converted to a data type with less precision
or smaller capacity, however, a run-time error message will occur
if data will be lost in such a conversion. Option Strict ensures
compile-time notification of these types of conversions so they
may be avoided.
In addition to the conditions described above, Option Strict generates
an error for:
- Any undeclared variable since it is implied that Option Strict
also means Option Explicit.
Late-binding.
Option Strict On ' Force explicit
variable declaration.
Dim MyVar As Integer ' Declare variables.
Dim Obj As Object
MyVar = 1000 ' Declared variable does not generate error.
MyVar = 1234567890.987654321 '
'Attempting to convert to an Integer will generate an error.
MyInt = 10 ' Undeclared variable generates error in Option
Strict mode.
Call Obj.Method1() ' Late-bound call generates an error
|
|