By default, the Visual Basic compiler enforces 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.
- Every narrowing type conversion must be specified with a type conversion keyword.
You can change either or both of these rules by resetting corresponding compiler options. If you change the type conversion rule, the compiler operates under permissive type semantics, which allows you to make narrowing conversions without conversion keywords.
If you change the variable declaration rule, you can then use typeless programming, which permits you to refer to variables without first declaring them. 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.
In This Section
- Implicit and Explicit Declaration
- Describes how to declare variables implicitly and explicitly.
- Type Checking
- Explains how and when the compiler permits implicit narrowing conversions.
- Object as the Universal Data Type
- Illustrates object-type data storage, conversions from other types, and special values.
- Efficient Use of Data Types
- Explains strong typing and when you should use it.