Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to check for duplicate rows/items in table?
08-03-2010, 09:42 AM (This post was last modified: 08-03-2010 09:43 AM by Aestival.)
Post: #1
How to check for duplicate rows/items in table?

    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
Find all posts by this user
Quote this message in a reply
08-03-2010, 11:42 AM
Post: #2
RE: How to check for duplicate rows/items in table?
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.
Find all posts by this user
Quote this message in a reply
08-03-2010, 11:54 AM (This post was last modified: 08-03-2010 11:55 AM by Aestival.)
Post: #3
RE: How to check for duplicate rows/items in table?
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
Find all posts by this user
Quote this message in a reply
08-03-2010, 12:10 PM
Post: #4
RE: How to check for duplicate rows/items in table?
See the belog script and let me know whether this helps you.


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
Find all posts by this user
Quote this message in a reply
08-03-2010, 01:17 PM (This post was last modified: 08-03-2010 01:18 PM by Aestival.)
Post: #5
RE: How to check for duplicate rows/items in table?
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..

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
Find all posts by this user
Quote this message in a reply
08-03-2010, 01:26 PM
Post: #6
RE: How to check for duplicate rows/items in table?
(08-03-2010 01:17 PM)Aestival Wrote:  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..

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
..............................................................................................
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.

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
Find all posts by this user
Quote this message in a reply
08-03-2010, 01:35 PM
Post: #7
RE: How to check for duplicate rows/items in table?
I still cnt get it..
nth happened..
is there sth wrong with my code?
Find all posts by this user
Quote this message in a reply
08-03-2010, 01:53 PM
Post: #8
RE: How to check for duplicate rows/items in table?
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.
Find all posts by this user
Quote this message in a reply
08-03-2010, 02:00 PM
Post: #9
RE: How to check for duplicate rows/items in table?
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.
Find all posts by this user
Quote this message in a reply
08-03-2010, 02:33 PM
Post: #10
RE: How to check for duplicate rows/items in table?
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?
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How to read specific rows Arena 1 203 04-07-2012 09:52 AM
Last Post: dineshkumar
  Way to check if a table is visible mv8167 4 457 02-07-2012 09:38 PM
Last Post: mv8167
  Problem in selecting multiple items in the weblist vijay44 7 1,818 08-10-2011 06:22 PM
Last Post: gaveyom
  Want to Automate clicking on Menu items Manan 6 1,192 09-16-2010 10:31 AM
Last Post: Manan
  How to count items in a weblist prachirao 6 2,947 05-04-2010 11:31 AM
Last Post: prachirao

Forum Jump:


User(s) browsing this thread: 1 Guest(s)