what is option explicit? what is the use of it?

Answers were Sorted based on User's Feedback



what is option explicit? what is the use of it?..

Answer / ritesh mahendrakar

You can declare variables with the Dim, Public or the
Private statement. Like this:

Dim myname
myname = "ritesh"

However, this method is not a good practice, because you
can misspell the variable name later in your script, and
that can cause strange results when your script is running.

If you misspell for example the "myname" variable
to "mynime", the script will automatically create a new
variable called "mynime". To prevent your script from doing
this, you can use the 'Option Explicit' statement. This
statement forces you to declare all your variables with the
dim, public or private statement.

Put the Option Explicit statement on the top of your
script. Like this:

Option Explicit
Dim myname
myname = "ritesh"

Is This Answer Correct ?    62 Yes 1 No

what is option explicit? what is the use of it?..

Answer / ravi kumar battula

Option explicit we declare at the top of the script so that
we can declare every variable as Dim or other data types.
Some times we do not declare variables, in that situation it
shows error if 'option explicit' is on in the script

Is This Answer Correct ?    24 Yes 3 No

what is option explicit? what is the use of it?..

Answer / uday kumar_anem

If we use 'Option Explicit', then we must declare the
varible before we use.
If you dont declare the varible, then it returns an error
message.

If you dont use 'Option Explicit' then no need of declaring
the variables.

Is This Answer Correct ?    20 Yes 5 No

what is option explicit? what is the use of it?..

Answer / rajendra

In VB script

option explicit forces the user to declare every variable
used in the code.

In VB Script is not mandatory to declare the variables.

VB script will be processed by windows scripthost.

Some time script host maynot haddle the undiclared
variables.

so it is a good practice option explicit on the top of the
script code.

once if u declare "option explicit" the each any every
variable must be dicalred before using it in code.

other wise it fires an error nad not allow to run the
script on Windows script host.

It is good coding practice to use "option explicit" on the
top of the code.

byeee

Rajendra Prasad Reddy
rajendra_penumalli@yahoo.com
+919885162742
hyderabad
india

Is This Answer Correct ?    10 Yes 2 No

what is option explicit? what is the use of it?..

Answer / shanker

If u are using Option Explicit, then variable declaration
in vb script becomes compulsory/mandatory.of course
Declaration is not mandatory in Vb script

Is This Answer Correct ?    7 Yes 2 No

what is option explicit? what is the use of it?..

Answer / kaps

In VB script it’s not necessary to declare a variable explicitly and we can assign a variable at any step we want. This can cause a problem if the project code is huge (while debugging for any bug in script), as the result may be different than expected.
E.g. we declare a string variable as 'strLogin' to save the login detail but later while assigning by mistake we write 'strLogi' then that Login detail will be saved to 'strLogi' instead of 'strLogin'. This will be a bug in script if we use 'strLogin' afterwards for some other inputs. To prevent such scenario VB script provides 'Option Explicit', which forces user to explicitly declare the variable before using it, otherwise script will throw an error at run time.

Option Explicit
Dim strLogin

Is This Answer Correct ?    3 Yes 0 No

what is option explicit? what is the use of it?..

Answer / sravani pasam

If we misspell variable in our Script then Script will automatically generates variable for that reason we r using'option explicit'

Is This Answer Correct ?    1 Yes 0 No

what is option explicit? what is the use of it?..

Answer / raju

Above answer is the opt answer.It is very helpful for me:)..

Is This Answer Correct ?    2 Yes 2 No

what is option explicit? what is the use of it?..

Answer / reddy

We can use Option Explicit function forcefully to declare variables before going to use that variables in script.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More QTP Interview Questions

Hi I am new to QTP. can u please answer to my qus... suppose 3 excel sheets are there * we are trying to check for login credentials for a page. userid from excel1 , password is from excel2 whether the page is opened or not that checkpoint is result is should be stored in excel 3.... this qus i have faced in IBM technical round... please tell script for above query ... please please

0 Answers   IBM,


How do we create and run the scripts with out using O.R. ?

5 Answers  


what is the general issues faced while using automation tool Qtp9.0

1 Answers   TCS,


What is data driver in qtp? Where we use it?

0 Answers  


Which Databases supports for QTP?

2 Answers  






How to analyzing test results using quicktest professional (qtp)?

0 Answers  


what are the attributes of QTP?

3 Answers  


What is debugging? How you debug your script?

0 Answers  


what r the 3 basic factor on which we determine to perform automation

6 Answers   AppLabs,


how to call a funtion in a script? i have saved the login scipt in notepad. with extension .vbs. But when i am calling the function with the keyword CALL <Function Name>. its not working out. can any one give me a clue how to call the external functions. with example.

3 Answers  


What exactly a frame Work means?what are the different type of frameworks done in QTP?why the caption for QTP given as advanced keyword driven?

4 Answers   Satyam,


Hi, I am using 2 excel sheet.First excel sheet works fine with the script, if it opens the 2nd excel sheet,it works fine,but after finish all the rows it is giving the following error in the following line. InValid Procedure call or argument Line (178): "Browser("name:="&result,"application version:=internet explorer 7").Page ("title:=bgt.*", "index:=0").WebList ("name:=SearchType","html id:=Select1","location:=0").Select SearchType1". I have seen a web article says that,If we use any vbscript friendly name it may gives the above error-Invalid procedure call or argument not sure,Am I using any VBScript frienlyName? in the above line? [but the same line is perfecly working for first Excel ] It is little urgent. Any Help Thanks you

0 Answers  


Categories