Micro Focus QTP (UFT) Forums
Using DP with variables - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Using DP with variables (/Thread-Using-DP-with-variables)



Using DP with variables - pjeigenn - 07-16-2010

Hi, i am new in this forum, I am from Argentina, sory if you don´t understand completely what i write.

I am using DP programming cause a web page have identical objects. I read that the correct form is using the parameter index or location, i chose index.
Descripting an object, is not posible to use variables as a description of the object am i right?

Example working:

Code:
aux=Environment.Value("ActionIteration")-7
    If (aux=0) Then
        Browser("Browser").Page("Page_4").Link("name:=Unicef -","html tag:=A","text:=Unicef -","Index:=0").Click
    End If

    If (aux=1) Then
        Browser("Browser").Page("Page_4").Link("name:=Unicef -","html tag:=A","text:=Unicef -","Index:=1").Click
    End If

Example NOT working:
Code:
aux=Environment.Value("ActionIteration")-7
Browser("Browser").Page("Page_4").Link("name:=Unicef -","html tag:=A","text:=Unicef -","Index:=aux").Click

The 2nd way is much better cause i can add new rows in the dataTable without touching the code, but it doesn´t work for me, what i am doing wrong? Is there any way to do what i am looking for?

Thanks


RE: Using DP with variables - Saket - 07-16-2010

as 'aux' is variable you can not use it within double quotes, use concatenation when use this way, see below -
Code:
Browser("Browser").Page("Page_4").Link("name:=Unicef -","html tag:=A","text:=Unicef -","Index:=" & aux).Click

hope this helps.


RE: Using DP with variables - sasmitakumari - 07-16-2010

If the line of code given by Saket does not work, Try this:
Code:
Browser("Browser").Page("Page_4").Link("name:=Unicef -","html tag:=A","text:=Unicef -","Index:=" & Cstr(aux)).Click



RE: Using DP with variables - Arun Prakash - 07-16-2010

What Saket is telling is absolutely right ,if we are passing a variable can not use it within double quotes, use concatenation

You can use the below code...

Code:
aux=Environment.Value("ActionIteration")-7
aux=Cint(aux)
Browser("Browser").Page("Page_4").Link("name:=Unicef -","html tag:=A","text:=Unicef -","Index:=" & aux).Click



RE: Using DP with variables - sreekanth chilam - 07-16-2010

@Sasmita: In your post, why do you think CStr should be used instead of Cint where (Environment.Value("ActionIteration")-7)
would return a Numerical value which would be assigned to Index.


RE: Using DP with variables - pjeigenn - 07-16-2010

Thanks to all, works great without cstr.


RE: Using DP with variables - Saket - 07-19-2010

Same thing in many different ways,
requesting all to not to confuse our freinds who are beginners, with your so many replies on same things.
Please wait for the original poster to reply first, or if you have a better solution.