|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Typeless Programming in Visual Basic
The Visual Basic compiler is capable of enforcing two rules that affect your source code:
Every local variable must appear in a declaration statement before being used in any other kind of statement. This rule is enforced by default.
Every narrowing type conversion must be specified with a type conversion keyword. This rule is not enforced by default.
Compiler Options that Change the Rules
You can change either or both of these rules by resetting corresponding compiler options. If you relax the type-conversion rule, the compiler operates under permissive type semantics, which allows you to make narrowing conversions without conversion keywords. For more information, see.
If you relax the variable-declaration rule, you can then use typeless programming, which permits you to refer to variables without first declaring them. For more information, see.
Typeless programming is not usually recommended, because it can lead to subtle execution errors involving data types. However, you might find it useful in some circumstances, such as porting an old application that did not declare variables.