QTP: Handling WebList Items with multi-values

WebList objects support an EntendSelect method to allow you to select more than one value. However, trying to express this in QTP can be a pain. How to make this simple? Well, here's how I implemented this:

I created a procedure (located in an external VBS file) that will accept the object (since it's registered to the WebList object), a delimited string of the values to select, and the delimiter. As you can see from the code below, it will parse the string, and select the values. As an extra option, you can pass “ALL” in the delimiter string, in which case all of the values in the ListBox are selected. One last note: you'll see that we check to make sure we can do multiple selects, too, and return an error if we can't.

A typical call by QTP might look like: Browser(“X“).Page(“X“).WebList(“X“).MultiSelect “Green|Red|Blue“, “|“

Naturally, there might be an easier way, and I welcome any suggestions. Enjoy! 

Public Sub MultiSelect(ByRef objListBox, ByVal strValuesToSelect, ByVal strDelimiter)
 Dim lngIndex    'As Long
 Dim strValues    'As String

 If objListBox.GetROProperty("select type") = "Extended Selection" Then
  If strDelimiter = "ALL" Then
   strValues = Split(objListBox.GetROProperty("all items"), ";")
        Else
   strValues = Split(strValuesToSelect, strDelimiter)
  End If

  For lngIndex = LBound(strValues) to UBound(strValues)
   Select Case lngIndex
    Case 0
     objListBox.Select strValues(lngIndex)
    Case Else
     objListBox.ExtendSelect strValues(lngIndex)
   End Select
  Next 'lngIndex
 Else
  msgbox "MultiSelect not supported by this control"
 End If
End Sub
RegisterUserFunc "WebList", "MultiSelect","MultiSelect"

«October»
SunMonTueWedThuFriSat
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234