what is use of optionexplicit in variable declaration

Answers were Sorted based on User's Feedback



what is use of optionexplicit in variable declaration..

Answer / murali krishna

hi,

i will not agree with u..

option explicit means.. it is the statement which is
declared during the variable declaration...

Option explicit statement is available to require explicit
declaration of all variable ... That means one may mispell
the variable name in one or more places,causing unexpected
results when your script is run..

Is This Answer Correct ?    5 Yes 0 No

what is use of optionexplicit in variable declaration..

Answer / aaa

In hurry i wrongly posted.

Option explicit
Dim a ---We are declaring them in advnace. (Dimension)
a=10

NOT error.

Option explicit
a=10
throws an error.

Is This Answer Correct ?    3 Yes 0 No

what is use of optionexplicit in variable declaration..

Answer / h.w thushara indika

If we used “Option Explicit” then we have to declare our
variables explicitly before they use. Examples in above
posts show this.

Explicit declaration has both pros and cons.

Advantages of Option Explicit:

1. Clearity of the Program enhanced by proper coding rules
• Professionals always instruct to use ‘Option Explicit’
on coding. This enables the programmer to enhance his code
to pre-declared standards.

2. Program code is easier to debug and read
• Programmer has clear idea about each variable he will
use because he has already declared what kind of data type
which will have by each variable. Therefore, even another
programmer can read the code and understand it easily than
an ‘option explicit’ off document.

3. Reducing mistyped variables instead of existing usable
variables
• User may use alternate names mistakenly for already
used variables. If you have ‘option explicit’, then the
mistyped variable will generate an compile error describing
an non-declared variable. But, if you haven’t ‘option
explicit’ in your program, this will be an programming error
which will give an erroneous result to end user.

4. Give more reliability on data
• ‘Option Explicit”cause programmer to have more
understanding on declared variables. This enables the
variable to have additional attention, and reduce any
attempt to misuse a variable unintentionally.

5. Can implement Error detection mechanisms using data types
• Data types define what kind of data that can be hold by
a given variable. If you try to assign date value
“21-08-1985” to character variable, then system will
automatically generate an exception or error. You can use
this error or exception to track the user, but you may want
to build several other mechanisms to track bad inputs if you
didn’t used ‘Option Explicit’

6. Faster memory allocation
• When declaring variables, VB assigns particular amount
of memory to that variable depending on its data type.
Typically, 32bits for Integer values etc… But if you are
looking to allocate memory while run-time, that will reduce
program’s performance.

7. No run-time dynamics
• Programmer can complete the building process as he has
given and knows all the resources needed by the program to
run. But, if program is designing memory capacities and
other things while run time, potential for generating an
error is much higher.

Disadvantages of Option Explicit:

1. Declaring variable names and its data types and all
other things take some time. It is not just about the
coding; programmer must design it at the specification stage
of the program. (That is even before he sit before an
computer to code the program)

2. After declaring an variable, the variable can have
fixed Range of values. This limits the productivity or the
usability of a variable, because when we don’t need the
existing value in a variable, still we can’t assign another
value which is not similar to variables’ data type.

3. When assigning values to declared variables, compiler
or interpreter need to check whether the input matches the
data type. This slows down the processing.

However, importance of ‘Option Explicit’ Statement has
increased by providing alternative mechanisms on ‘Option
Explicit’ disadvantages. For example, newer VB versions have
integer data types in different modes – 16 bit, 32 bit etc…

H.W Thushara Indika from Sri Lanka

Is This Answer Correct ?    2 Yes 0 No

what is use of optionexplicit in variable declaration..

Answer / aa

If we don't use it, we can declare variables in vbscript
without declaring them in advance.
Ex:

option explicit
a=10

This throws an Error.

If don't use... Option explicit
a=10
doesnot throw an error.

Is This Answer Correct ?    0 Yes 0 No

what is use of optionexplicit in variable declaration..

Answer / ram

Option explicit on means we have to declare the variable
ex dim a

Option explicit off means we dont want to declare the
variable(by default variant)

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More QTP Interview Questions

I had created the new virtual objects for web application buttons. how to add those virtual objects into object repository. Previously i had used Gui map in winrunner for capturing virtual objects for web application. Please help me regarding this. need your answer quickly

1 Answers  


How to sendKeys in QTP? Diff b/w sendkeys and device replay? Diff b/w function and Sub? Diff b/w Array and List Different Types of running Keys other than Fast, slow,Normal mode Regular expression for http://newtours.demoaut.com Difference between \w and \W How to generate script button Recording Types Different Types of Actions? Using DP performance degrades, If Yes why? How to close all the opened browsers? Diff b/w SystemUtil.Run and invoke application? If qtp not recognized the combo box How to select values from drop down?

0 Answers  


Reverse string without mid or streverse function.

1 Answers   Deloitte,


How to record objects of Windows taskbar

2 Answers   RoboSoft,


Hi I know two types of testing processes. 1. Reaquirments stage,test design,code review's, Design review's, Test Plan, Test Cases design, test execution, Defect Reporting and tracking, UAT, Signoff. 2.Test Initiation , Test Plan, Test Design, Execution,Bug tracking, UAT, Sign off.

0 Answers  






Some time when i wanna learn the object i face issue like i am not able learn the object in proper manner... eg:for text bo on web page it should learn as webedit but some times it reads as winobject:internetexpoler-server, because of this i have to uninstall the qtp and re-install it again when i do this it reads the object perfectly.....plz suggest the soln

0 Answers  


How can i learn Descriptive programming in QTP. Please reply.

3 Answers  


Plz Explain How to access Or Store Script from VSS? Explain Real time work (qtp) where you store folders and next to how to you access that folders and how you maintain folders in VSS ? What are the Menu's in VSS? Suppose in Manual, by using Checkin Checkout u can access documents. how you access in QTp REal time?

0 Answers   CTS,


Hi Friends, If you got one Bug , and you are insert that bug in bug tracking tool , and you need to attach SC's (screen shots) also. how to tae SC's , in your organization any separate tools available to take SC's. please provide Ans. its urgent... Thanx in advance

3 Answers  


how we can take data in the username field text box into variable in web application explain with example and give all functions to get data into variables

1 Answers  


What is the keyword view and expert view in qtp?

0 Answers  


I want to install qtp software in my system, My operating system is vista . Anybody please suggest me how to get QTP software with licence key

2 Answers  


Categories