Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to check for duplicate rows/items in table?
#1
Not Solved
    Hi,
I am checking whether there are any duplicate items in my table.
However the rows in my table will vary which mean I do not know how many rows I will have in my table unless I do a row count.
In this case, I would like to check if I have any duplicate "Level". And in the screenshot(attached), there is duplicate "Level".
It should then return a dialog box as an error.
So how do I write my code using loop method?
thanks
Reply
#2
Not Solved
First you count how many rows are there. Get the 1st row value of the "Level" column and compare it with the rest of the values of the same column. If any matches found then no need to proceed further and exit from the function (If you are going to test this one by preparing a function). If no matches found then you get the 2nd row value of the "Level" column and compare it with the rest of the values of the same column.
Reply
#3
Not Solved
Hey thx for ur reply..
Yes, this is what I'm thinking of doing..
but my problem now is I dunno how to compare..
Do you mind providing me with a sample code?
thx very much Big Grin
Reply
#4
Not Solved
See the belog script and let me know whether this helps you.


Code:
intRowCnt = Object.Table().RowCount

Public Function Comapre_Table_Element(intRowCnt)

    If (intRowCnt = 0 Or intRowCnt = 1) Then

        blnStatus = False
        
    End If

    For intItemCntx = 0 To intRowCnt - 1
    
        strGetVal1 = Object.Table().GetCellData(intItemCntx, "Level")
    
        For intItemCnty = intItemCntx + 1 To intRowCnt - 1
    
            strGetVal2 = Object.Table().GetCellData(intItemCnty, "Level")
    
            If (StrComp(strGetVal1, strGetVal2, VbTextCompare) = 0) Then
    
                blnStatus = False
    
                Exit For
                
            Else

                blnStatus = True
                
            End If
    
        Next
    
        If (blnStatus = False) Then
    
            Exit For
            
        End If
    
    Next

    Comapre_Table_Element = blnStatus

End Function
Reply
#5
Not Solved
I'm not sure if I did it correctly.
But when I run my test nth happen..
here's my code..
(my table row default value is 1)
I dunno where is the problem..

Code:
nTotalRow = Browser("bwTPeSA").Page("bwTPeSA.pgMySub").WebTable("bwTPeSA.mySub.tblSubjects").RowCount
MsgBox  nTotalRow
Function ComapreTableElement(nTotalRow)
If (nTotalRow = 1 Or nTotalRow = 2) Then
blnStatus = False
End If
For intItemCntx = 2 To nTotalRow
strGetVal1 =Browser("bwTPeSA").Page("bwTPeSA.pgMySub").WebTable("bwTPeSA.mySub.tblSubjects").GetCellData(intItemCntx, 4)
For intItemCnty = intItemCntx + 1 To nTotalRow
strGetVal2 = Browser("bwTPeSA").Page("bwTPeSA.pgMySub").WebTable("bwTPeSA.mySub.tblSubjects").GetCellData(intItemCnty, 4)
If (StrComp(strGetVal1, strGetVal2, VbTextCompare) = 0) Then
blnStatus = False
MsgBox "No Duplicate"
Exit For
Else
blnStatus = True
MsgBox"Duplicate"
End If
Next
If (blnStatus = False) Then
Exit For
End If
Next
ComapreTableElement = blnStatus
End Function
Reply
#6
Not Solved
..............................................................................................
I did one mistake in the script. I didn't use the Exit Function statement when the row count is 0 or 1 as that point of time we don't need to compare.

Code:
intRowCnt = Object.Table().RowCount

Public Function Comapre_Table_Element(intRowCnt)

If (intRowCnt = 0 Or intRowCnt = 1) Then

blnStatus = False

Exit Function

End If

For intItemCntx = 0 To intRowCnt - 1

strGetVal1 = Object.Table().GetCellData(intItemCntx, "Level")

For intItemCnty = intItemCntx + 1 To intRowCnt - 1

strGetVal2 = Object.Table().GetCellData(intItemCnty, "Level")

If (StrComp(strGetVal1, strGetVal2, VbTextCompare) = 0) Then

blnStatus = False

Exit For

Else

blnStatus = True

End If

Next

If (blnStatus = False) Then

Exit For

End If

Next

Comapre_Table_Element = blnStatus

End Function
Reply
#7
Not Solved
I still cnt get it..
nth happened..
is there sth wrong with my code?
Reply
#8
Not Solved
As you told that in that table row default value is 1. So if we consider row count as 1 then no need compare and even though you are trying to access the function then it will return False.

The function is designed for returning only the True or False value.
Reply
#9
Not Solved
i dun get what u mean..
default value is 1 mean even without adding anything to the table, the rows count is alrdy 1 in the first place.
Reply
#10
Not Solved
Hi Aestival,

ok i got your point.

You add few rows in the table and use the latest function and pass the rowcount to that function and see what the function is returning?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to fetch items from WpfList in UFT saurabhkumar_gupta 0 2,441 03-08-2015, 09:17 PM
Last Post: saurabhkumar_gupta
  How to Delete Rows with duplicate values in 1 columns in excel thru QTP. arpan 0 2,805 02-09-2015, 08:47 PM
Last Post: arpan
  Can't locate items on Win7 Desktop RandomGrin 0 2,070 01-30-2015, 10:55 PM
Last Post: RandomGrin
  How to get center data value in a odd number of rows and columns web table ... sai rajesh 0 2,787 11-13-2013, 10:24 PM
Last Post: sai rajesh
  to count the number of used rows in a particular column sujaravi123 3 11,149 06-12-2013, 03:17 PM
Last Post: sujaravi123

Forum Jump:


Users browsing this thread: 4 Guest(s)