Answer Posted / 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 |
Post New Answer View All Answers
Explain the asc function?
What is the output of a + b in vbscript if a = 5 and b = 10?
What is the purpose of regexp object in vbscript?
Mention the rules for using option explicit statement?
What purpose does ‘on error resume next’ serves?
In html file what is an ideal position to include vbscript?
What is the purpose of on error resume next statement?
How many types of operators are available in the vbscript language?
How to create a cookie using vbscript?
How will you get the largest subscript of an array in vbscript?
Hellow friends, I am learning QTP,but here problem is VB script. please guide me how to learn VB script w.r.t QTP and if you know any books tell me or if you have any materials or any use full material or any else w.r.t QTP please post me p.p.sekhar
Explain about adodb.stream class?
Which loop is used in case of arrays in the vbscript language?
How to scroll down a page while recording in qtp. suggest me any method apart from low level recording.
What is dictionary object in vbscript? Explain?