Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the use of DIM ?
#1
Not Solved
Hi ,

What is the use of Dim , Option Explicit ?
While writing script if we didn't write Dim and Option Explicit the script will rum or not?

Thanks
Reply
#2
Not Solved
Dim is for declaring a variable.and Option explicit makes it mandatory for the script writer to declare the variable.

If you have Option Explicit in your script, and you don't declare the variable using Dim ,the script throws an error.
Reply
#3
Not Solved
While writing script if we didn't write Dim and Option Explicit the script will rum or not?

Yes it runs successfully
Reply
#4
Not Solved
Hi,
There are two types of Variable Declaration Explicit and Implicit

Explicit way of Declaration
Dim str1
str1 = "Test"

Implicit way of Declaration
str1 = "Test"

When you use Option Explicit you should declare the variable by Explicit way. Otherwise you will get "Error 500" -"Variable is undefined"



Reply
#5
Not Solved
I personally am starting like Option Explicit more and more. It keeps me from making dumb mistakes like this:

Code:
dim recurring
recurrring=browser(<whatever>).page(<whatever>).WebLink(<whatever>).GetROProperty("innertext")
if recurring="clickme" then
...

I have done this too many times - declared a variable and then used a mis-typed version of the variable later on. Infuriating!
Reply
#6
Not Solved
if you use 'option explcit' in your script you should declare the variable in the script.otherwise u will get error.

Dim is used for declaring the variables.
Reply
#7
Not Solved
That's exactly what I want. I want to declare the variable name I want to use. Then if I try to use a mis-typed the variable name, QTP throws an error so I know I screwed it up. That way I don't get weird results when the script goes into "production".
Reply
#8
Not Solved
Hi,

When there are more number of variables it is better to use option Explicit. That will help us in debugging if go wrong with the variables any where in the script.

krr
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)