Datasheet

Figure 1-15: The Compile tab contains important properties for controlling code generation.
The second compiler option is Option Strict. When this option is turned off, Visual Studio allows your
code to implicitly convert from one data type to another, even if the types are not always compatible.
For example, Visual Basic will allow the following code to try to copy the string
s into the integer i.
If the value in the string happens to be a number, as in the first case, this works. If the string is not a
number, as in the second case, this fails at runtime.
Dim i As Integer
Dim s As String
s = “10”
i = s ‘ This works.
s = “Hello”
i = s ‘ This Fails.
If you set Option Strict to On, the IDE warns you that the two data types are incompatible, so you can
easily resolve the problem while you are writing the code. You can still use conversion functions such
as
CInt, Int, and Integer.Parse to convert a string into an Integer, but you must take explicit action
to do so. This makes you think about the code and reduces the chances that the conversion is just an
20
Part I: Getting Started
37055c016.qxd 4/8/07 12:46 PM Page 20