VB.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  VB.NET Option Strict [On | Off]

Option Strict is prevents program from automatic variable conversions, that is implicit data type conversions .

Option Strict [On Off]

By default Option Strict is Off

From the following example you can understand the use of Option Strict.

VB.NET Source Code

  Public Class Form1
	Private Sub Button1_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles Button1.Click
		Dim longNum As Long
		Dim intNum As Integer
		longNum = 12345
		intNum = longNum
		MsgBox(intNum)
	End Sub

End Class

The above program is a normal vb.net program and is in default Option Strict Off . Because its Option Strict Off we can convert the value of Long to an Integer.

Take a look at the following program.

         VB.NET Source Code Download           Print Source Code
         VB.NET Option Strict [On | Off] - Download
        
C# Tutorial

Option Strict On
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

        Dim longNum As Long
        Dim intNum As Integer

        longNum = 12345
        intNum = longNum

        MsgBox(intNum)
    End Sub
End Class

When you write this source code the compiler will shows the message
"Option Strict On disallows implicit conversions from 'Long' to 'Integer'"

The compiler generate error because in the program we put "Option Strict On" and prevent the program from automatic conversion.


VB.NET Language Basics Related Contents
*     VB.NET data types
*     VB.NET Implicit conversion and Explicit Conversion
*     VB.NET Access Specifiers
*     VB.NET Exceptions
*     VB.NET Option Explicit
*     VB.NET On Error


   Home      VB.NET      C#
VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
*     VB.NET DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.