Why do we use Option Explicit?

Answers were Sorted based on User's Feedback



Why do we use Option Explicit?..

Answer / farah

If we declare variables in option explicit and if
undeclared variabled are used in the code then it displays
error messages

Is This Answer Correct ?    6 Yes 0 No

Why do we use Option Explicit?..

Answer / jim c

Option Explicit forces the programmer to declare all
variables, rather than letting them be implicitly declared
upon their first use.
This enforces good programming practices and avoids
ambiguity of variable scope.
Here are some simple code examples:
'*************************************
i = 1
Call mySub
WScript.Echo i

Sub mySub
i = 10
End Sub
'*************************************
In this first example, because the programmer is relying on
implicit variable declaration, the subroutine is modifying
global variable i, and the printed result is 10. Now, modify
the code so that the variables are declared:
'*************************************
dim i
i = 1
Call mySub
WScript.Echo i

Sub mySub
dim i
i = 10
End Sub
'*************************************
Now, we actually have two different variables named i, one
with global scope, and one with local scope. The printed
result is now 1.
Since a lot of programmers use i in For..Next loops, you can
see how this could result in unpredictable results without
explicit variable declaration

Is This Answer Correct ?    8 Yes 3 No

Why do we use Option Explicit?..

Answer / rekha

there are different ways of declaring variables
this option is used to declare multiple values

Is This Answer Correct ?    6 Yes 3 No

Why do we use Option Explicit?..

Answer / veena

vb supports a datatye called variant which can store any
interger,variable,float..by using option explicit it will
not allow the variables to declare implicitly.

Is This Answer Correct ?    3 Yes 0 No

Why do we use Option Explicit?..

Answer / harry

hi,
when you declare varible you use option Explicit as a
first line of your script .
ex
DIM name

if you do any spelling mistake like nime instead of name
then vb will take this as an new verible and endup giving
unpredictable result while runing.

Is This Answer Correct ?    2 Yes 0 No

Why do we use Option Explicit?..

Answer / p.shivakumar

option explicit is used to declare variable where implicit
command without declaration of variable

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More VB Script Interview Questions

what is resorceallocation

0 Answers  


i need to login to my yahoo accoutnt using VB Script, automating the operation of webobjects, even launching of IE. How?

1 Answers   Mphasis,


Write a program to print all lines that contains a word either “testing” or “qtp”

2 Answers  


Hello friends..... Can any give the methods for Ms-Access, and Mozilla firefox in Automation Object Model in QTP. Please give me currect answers... if you do not understand my question please don't give answers. Thanking you.

0 Answers  


how to delete folder test3,test4 and test5 using vbscript?

2 Answers  


What are class properties?

0 Answers  


write a vb script to display apple that is 1st a should be displayed then ap then app then appl then apple

7 Answers  


i have to open a notepad having no. of words in dat file by recording in qtp and then find a particular word and display true or false

0 Answers  


Explain the .wsf files?

0 Answers  


Write a Script for ATM in QTP

0 Answers  


write any ttest cases using check points and parameterization

0 Answers  


how to write function to validate the number of characters entering into the text box?

2 Answers   TCS,


Categories