Wednesday, May 15, 2013

VB.NET Option Explicit

Today I will tell you about using the Option Explicit statement. The Option Explicit has two modes. On and Off mode. If Option Explicit mode in ON , you have to declare all the variable before you use it in the program . If not , it will generate a compile-time error whenever a variable that has not been declared is encountered .If the Option Explicit mode is OFF , Vb.Net automatically create a variable whenever it sees a variable without proper declaration

By default the Option Explicit Statement is always On.

Option Explicit Off
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
someVariable = "Option Explicit ON"
MsgBox(someVariable)
End Sub
End Class


Here "someVariable" is not declared , because the Option Explicit Of , without any compiler error you can continue the program.

No comments:

Post a Comment