nivi
nivi

Reputation: 11

Qtp select item using regex

I am studying qtp, I have a list field and I want select an item form that. For that I am using the following code and it's was generate using record option in qtp. now the system using Select "123" for selecting instead 123 I want ^1\d\d

Actual code

VbWindow("frmMDI").VbWindow("frmcheckIn").VbComboBox("cboRoomNo").Select "123"

I am tried the following code but it's not working

VbWindow("frmMDI").VbWindow("frmcheckIn").VbComboBox("cboRoomNo").Select ("^1\d\d")

Upvotes: 1

Views: 874

Answers (1)

Motti
Motti

Reputation: 114805

VbComboBox.Select doesn't support regular expressions. You'll have to iterate over all the values and perform the regular expression matching yourself.

Set re = New RegExp
re.Pattern = "^1\d\d"
Len = VbWindow("frmMDI").VbWindow("frmcheckIn").VbComboBox("cboRoomNo").GetItemsCount()
For i = 0 to Len - 1
    item = VbWindow("frmMDI").VbWindow("frmcheckIn").VbComboBox("cboRoomNo").GetItem(i)
    If re.Test(item) Then 
         VbWindow("frmMDI").VbWindow("frmcheckIn").VbComboBox("cboRoomNo").Select(item)
         Exit For    
    End If
Next

Upvotes: 4

Related Questions