Micro Focus QTP (UFT) Forums
Inserting variable values into Descriptive Programming Functions - 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: Inserting variable values into Descriptive Programming Functions (/Thread-Inserting-variable-values-into-Descriptive-Programming-Functions)



Inserting variable values into Descriptive Programming Functions - eske99 - 10-30-2015

Hello All,
I'm trying to use a general function in my function library to click links.  I used variables to define property values.  The values for the link properties are coming from the same row as my Teststeps in the Excel file from columns IP1 and IP2.  However, when the clickLink function is called the second time it's still using the previous values ie. not pulling values from current Teststep row.

Some columns I could use as identifiers are TSID, Keywords, IP1, IP2

I would really appreciate any help fixing this!

Function Library Code:

Code:
Function clickLink(dData, dData2)
   dData=datatable.Value("IP1","dTeststeps")
   dData2=datatable.Value("IP2","dTeststeps")
   Browser("micclass:=Browser").Page("micclass:=Page").Link("name:="&dData,"html tag:=A", "text:="&dData2).Click
End Function

Main Code Call from Select/Case:

Code:
Case "clickLink"
dData=datatable.Value("IP1","dTeststeps")
dData2=datatable.Value("IP2","dTeststeps")
Call clickLink(dData, dData2)

Thanks in advance,
Scott K.


RE: Inserting variable values into Descriptive Programming Functions - supputuri - 11-04-2015

You have to set the Data table row by using "SetCurrentRow" method so that the Row will change from previous to next row then you should be good.

Code:
'i - is the row which you want to set
DataTable.SetCurrentRow(i)

Alternatively you can use
Code:
DataTable.SetNextRow
After clicking so that the row selection will change to next row.


RE: Inserting variable values into Descriptive Programming Functions - vinod123 - 12-18-2015

Code:
Dim Rowcount, webrowcnt
Rowcount=datatable.getsheet"Sheet name".GetRowCount

For i=1 to Rowcount
Datatable.GetSheet"Sheet name".SetCurrentRow(i)
Browser("").Page("").Link("").Click
Browser("").Page("").WebEdit("").Set DataTable("Row1", dtLocalSheet)
Browser("").Page("").WebButton("").Click

webrowcnt=Browser("").Page("").WebTable("").RowCount

For n=3 to webrowcnt  (note: n=3 because the data I need starts on row 3)
If webrowcnt > 3 Then (note: this is where I want it to create a new row if there is more than 3 rows of data)
For i=4 to webrowcnt
some code here to create however many rows of data the account number has.
Next
End If
column1 = Browser("").Page("").WebTable("").GetCellData(n, 1)
DataTable("column1", dtLocalSheet)=column1
column2 = Browser("").Page("").WebTable("").GetCellData(n, 2)
DataTable("column2", dtLocalSheet)=column2
column3 = Browser("").Page("").WebTable("").GetCellData(n, 3)
DataTable("column3", dtLocalSheet)=column3
column4 = Browser("").Page("").WebTable("").GetCellData(n, 4)
DataTable("column4", dtLocalSheet)=column4
column5 = Browser("").Page("").WebTable("").GetCellData(n, 5)
DataTable("column5", dtLocalSheet)=column5
column6 = Browser("").Page("").WebTable("").GetCellData(n, 6)
DataTable("column6", dtLocalSheet)=column6

Browser("").Page("").Link("").click (note: link to return to home page to  restart on new account number)
Next