Why do we use Option Explicit?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
Please let me Know regarding any material regarding VB Scripting which should be easily understandable for Beginners.
Why to add checkpoint in QTP What's the purpose of checkpoints & how to add it
write a vb script to display the size of the folder,date created and name of the folder
Mention if qtp generates vbscript code as we record actions, can't it possible to directly write using vbscript code when qtp does the same thing too?
write a vb script to display ***** ***** ***** ***** *****
Hi Friends my Question is very simple,in Manual testing when we click on a hyper link it directs us to the relavent page or it re-directs us to the current page,so there we can easily write testcase but same thing if we do in automation script using QTP & need to generate report using Reporter.report event how we will do it?thanks in advance...
How to identify column in VSFlexgrid? My VSFlexgrid window is identified as 'Active X Control'
When are redim statement and preserve keyword used in the vbscript language?
write a vb-script code to delete all the mails in my gmail in the year 2011
How can you create a file object to work with the files in the vbscript language?
Explain the arrays in vb script?
What is the purpose of drive object of scripting.filesystemobject class in vbscript?