Micro Focus QTP (UFT) Forums
What is the use of DIM ? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Interview Questions (https://www.learnqtp.com/forums/Forum-UFT-QTP-Interview-Questions)
+--- Thread: What is the use of DIM ? (/Thread-What-is-the-use-of-DIM)



What is the use of DIM ? - shyam.emmadi - 06-24-2011

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


RE: What is the use of DIM ? - prachi.aug23 - 07-07-2011

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.


RE: What is the use of DIM ? - rajpes - 07-07-2011

While writing script if we didn't write Dim and Option Explicit the script will rum or not?

Yes it runs successfully


RE: What is the use of DIM ? - hariraman.g - 08-09-2011

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"






RE: What is the use of DIM ? - tdevick - 08-09-2011

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!


RE: What is the use of DIM ? - Kasanagottu - 08-10-2011

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.


RE: What is the use of DIM ? - tdevick - 08-10-2011

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".


RE: What is the use of DIM ? - krr - 11-24-2011

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