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
In html file what is an ideal position to include vbscript?
How will you get a string with the specified character the specified number of times in vbscript?
Dear All, I am geting below IE error whilie executing the QTP scripts in Batch mode "Internet Explorer has encountered a problem and needs to close. We are sorry for the inconvenience." can any one suggest me how to resolve this issue . Thanks Balaji
Give me sm ideas to write Vbscripts abt protocol testing abilash700@gmail.com.
write a function to read the items from combobox of Flight reservation & save in excel (QTP)??
How can you destroy an object in vbscript?
What is byref and byval parameters in vbscript?
Which command is used for writing text on a page?
Anyone have qtp11.0 crack?
Difference between dim,public and private variables in vb script?
How will you reverse a string in vbscript?
Mention characteristics of sub procedures?
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?
Explain the .wsf files?
What are subprocedures in vbscript?