0% found this document useful (0 votes)
212 views1 page

Forcing Variable Declaration in VB

The document discusses the Option Explicit statement in VB.NET which controls whether variables must be declared before use. With Option Explicit On, variables must be declared and errors will occur for undeclared variables. By default, Option Explicit is set to On in VB.NET.

Uploaded by

Anshul Saxena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
212 views1 page

Forcing Variable Declaration in VB

The document discusses the Option Explicit statement in VB.NET which controls whether variables must be declared before use. With Option Explicit On, variables must be declared and errors will occur for undeclared variables. By default, Option Explicit is set to On in VB.NET.

Uploaded by

Anshul Saxena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

forcing variable declaration in vb.

net
Option Explicit statement ensures whether the compiler requires all variables to be explicitly declared or not
before it use in the program.
Option Explicit [On Off]

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 is On

With the Option Explicit On , you can reduce the possible errors that result from misspelled variable names.
Because in Option Explicit On mode you have to declare each variable in the program for storing data.
Take a look at the following programs, it will give you a clear picture of Option Explicit.
The following program is a normal vb.net program , so the default mode of Option Explicit On is using. The
default is Option Explicit On , so we do not need to put it in the source code.
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 someVariable As String
someVariable = "Option Explicit ON"
MsgBox(someVariable)
End Sub

End Class

You might also like