Below QTP example shows how we can find out the column position/number for the given column name in the webtable using QTP.
Suppose you know the column name as "Quantity", then you can get it's position using below line of code.
Below function will return the position of the given column in the table. If the column is not found in the table, -1 is returned.
print GetColumnNumber(ObjParent.Webtable("mytable"), "Quantity")
Function GetColumnNumber(byval table, byval columnName)
Result = false
intColumnCount = table.ColumnCount(1)
print "row count " & intColumnCount
For j = 1 to intColumnCount
curColumn =table.GetCellData (1, j)
print curColumn
'It is important to remove the extra spaces using trim function to match the column name properly
If ucase(trim(columnName)) = ucase(trim(curColumn)) Then
GetColumnNumber=j
Exit Function
end if
next
GetColumnNumber = -1
End Function
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts. You can write to me at reply2sagar@gmail.com
Suppose you know the column name as "Quantity", then you can get it's position using below line of code.
Below function will return the position of the given column in the table. If the column is not found in the table, -1 is returned.
print GetColumnNumber(ObjParent.Webtable("mytable"), "Quantity")
Function GetColumnNumber(byval table, byval columnName)
Result = false
intColumnCount = table.ColumnCount(1)
print "row count " & intColumnCount
For j = 1 to intColumnCount
curColumn =table.GetCellData (1, j)
print curColumn
'It is important to remove the extra spaces using trim function to match the column name properly
If ucase(trim(columnName)) = ucase(trim(curColumn)) Then
GetColumnNumber=j
Exit Function
end if
next
GetColumnNumber = -1
End Function
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs