
File-Level Programming Elements
When you start a project or file and open the code editor, you see some code already in place and in the correct order. Any code that you write should follow the following sequence:
Option statements
Imports statements
Namespace statements and namespace-level elements
If you enter statements in a different order, compilation errors can result.
A program can also contain conditional compilation statements. You can intersperse these in the source file among the statements of the preceding sequence.
Option Statements
Option statements establish ground rules for subsequent code, helping prevent syntax and logic errors. The Option Explicit Statement (Visual Basic) ensures that all variables are declared and spelled correctly, which reduces debugging time. The Option Strict Statement helps to minimize logic errors and data loss that can occur when you work between variables of different data types. The Option Compare Statement specifies the way strings are compared to each other, based on either their Binary or Text values.
Imports Statements
Namespace Statements
Namespaces help you organize and classify your programming elements for ease of grouping and accessing. You use the Namespace Statement to classify the following statements within a particular namespace. For more information, see Namespaces in Visual Basic.
Conditional Compilation Statements
Conditional compilation statements can appear almost anywhere in your source file. They cause parts of your code to be included or excluded at compile time depending on certain conditions. You can also use them for debugging your application, because conditional code runs in debugging mode only. For more information, see Conditional Compilation Overview.