Tuesday, 11 June 2013

How to Get Column No for any field/ColumnName in WebTable

Below is a piece of code which should be part of ur .QFL file.this will return the column no for specfic cell text(in specfic row).
this is very essential function as by defect VBScript/QTP lib provide only row no not column for cell data

Function gettingColNo( tbleObj,ColName,RowNo) 
 colcount= tbleObj.ColumnCount(row)
  For colNum =1 To colcount
   ColHeader = tbleObj.GetCellData(RowNo,colNum)
   If inStr(Lcase(ColHeader),Lcase(ColName)) > 0 Then
    blnResult = True
    gettingColNo= colNum
    Exit For
   End If
  If  colNum > colcount  Then
    blnResult = False
    'your custom code to hadle false condtion, like reporting to parent function or qc
  End If
End Function

How to Get a unique row in a webTable Object with Defined column Names

Recently I came across the situation where I need to insert a row in a table and then the validate the
same in the table, whether the row is successfully added or not.
I have written a piece of code which i think will be usefull for u guys in your projects as well.
This is a very common feature of PRPC framework based applications.In which almost everything is composed of Tables
Now there are the few thing we need to make sure that the row is added .

1. We need to check the row count of the table before the row is inserted.Which we can later
    compare  to the row count after the insertion.
2. Once we are sure that the row is added. we need to make sure we have the exact row added which
     we were supposed to .

now for this step 2 we can write a func. which we can use in projects.

I believe it will be usefull for u guys.

 Function Fn_UniqueFirstRow(tblObj,strColNames,strValues)

aryColNames=Split( strColNames,";")
If rowCount>0 Then
 If UBound(aryColNames)=UBound(aryValues) Then
  For rowCounter=1 to rowCount
   '---compile the actual row Value for each row and compare
   For colCounter=0 to  colCount
    '----Now here I m expecting that you have some function to get column   
    '---number, 'if not i will be posting that as well later
    colNumber=Fn_ColumnNumber( colName,tblObj,1)
      If colCounter=0 Then
     End If
    If StrComp(Trim(MsgSTR),Trim(strValues)) = 0 Then
     strRowNum=rowCounter&";"&" Unique is row found with given values"
     Exit For
    End If
   If  Not rowFound Then
    strRowNum="-1"&";"&"Unique row doesnt exist"
   End If    
    strRowNum="-3"&";"&"Col Names and col Values arent in same number"
   End If
   stRowNum="-2"&";"&"Table has no rows"
  End If
 End Function