Forum Discussion

DevPerera's avatar
DevPerera
Occasional Contributor
9 years ago
Solved

How to check whether drop-down contain duplicate values or not?

Hi All,

 

I want to know how to check whether drop-down contain duplicate values or not?

I am using Testcomplete version 11.

Also I am uing VB scripts.

My appraoch is first creat an array with all the drop-drown value, then find array contain any duplicate value or not.

 

I try to creat an array with dropdown values, but I am getting an error saying type mismatch.

For j = 0 To MyObject.wItemCount
MyArray(j) = MyObject.wItem(j)
Next

 

..................

Thanks

Dev

  • DevPerera's avatar
    DevPerera
    9 years ago

    Hi Colin,

     

    Thanks for your reply.

    However I found a solution from some other site, written in VB.

     

    Following is my code.

    Sub Check_duplicate()
    listcount = myselectobject.wItemCount
    listcount = listcount - 1
    listone = myselectobject.wItemList
    Log.Message "select object list; " & listone
    aList = split(myobj1,";")
    For x = 0 To listcount
    If InStr(sNewList,(aList(x) & ";")) <= 0 Then
    sNewList = sNewList & aList(x) & ";"
    End If
    Next
    listtwo = Left(sNewList,Len(sNewList)-1)
    Log.Message "select object list; " & listtwo
    If listone <> listtwo Then
    Log.Message "duplicate found"
    Else
    Log.Message "No duplicate found"
    End If

    End Sub

     

    ...................

    Thanks

    Dev

4 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    My guess is that wItem(j) is an object, so you must change

    MyArray(j) = MyObject.wItem(j)

    to

    Set MyArray(j) = MyObject.wItem(j)

     

    Also, if the drop-down supports a property that contains a complete list of all its values, you may consider using regular expressions (with HISUtils object in TestComplete) to check for the duplicates. The implementation and performance with regular expressions may be better.

     

    • DevPerera's avatar
      DevPerera
      Occasional Contributor

      Hi Alex,

       

      Thanks for the reply, but I didnt know how to use "HISUtils" to find duplicate values.

      If you can share some code example its whould be great help for me.

       

      .............

      Thanks

      Dev

      • Colin_McCrae's avatar
        Colin_McCrae
        Community Hero

        http://support.smartbear.com/viewarticle/71165/

         

        Also, as Alex says, many dropdowns have a property containing all selections, rather than a series of objects you have to check in array.

         

        Something like:

         

        <list>.AllValues() = "Opt 1|Opt 2|Opt 3"

         

        Or something along those lines. Just the selection text with some sort of separator. All in one string. Much easier to check.