Absent Member.
Absent Member.
1009 views

Searching for and selecting row in Datawindow

Jump to solution

I have a PbDataWindow that I would like to search for a row with specific text in a column and then activate the cell. Unfortunately I've not been able to locate the method for doing so. Right now I'm having to use SelectCell and identify the row then ActivateCell for that row number, but that row can change periodically depending on the environment I'm in.

 

Thoughts? Thanks

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

You can write a custom method, below is the rough idea. You can write it your way.

 

To find the column index:
row = 1 'or 0 i.e. headers row no
For col = 1 To objPBDW.ColumnCount
       If objPBDW.GetCellData(row, col) = strData Then            
            Exit For
       End If
Next

If column names property is available, you can use that value also to find the column index.

To find record with text:
For row = 1 To objPBDW.RowCount
      If objPBDW.GetCellData(row, col) = strData Then
          Exit For
      End If
Next
Accept as solution/Give Kudos to the author if the piece of information answered/helped you to solve your problem.
All the thoughts here are mine not related to my employer nor anyone.
Test Automation Ecstasy

View solution in original post

0 Likes
8 Replies
Absent Member.
Absent Member.
Hi get number of Rows Loop through all rows and get cell value from each row if that matches with the exepcted value, then get the row number and Exit the Loop. Ex: ' this is just for idea. Rws= PbDataWindow.Rowcount For i=1 to Rws RwValue= PbDataWindow.getacellvalue(i, ColumnName) if RwValue="Expected Value" then PbDataWindow.activatecell(i, ColumnName) Exit for End if Next
0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

You can write a custom method, below is the rough idea. You can write it your way.

 

To find the column index:
row = 1 'or 0 i.e. headers row no
For col = 1 To objPBDW.ColumnCount
       If objPBDW.GetCellData(row, col) = strData Then            
            Exit For
       End If
Next

If column names property is available, you can use that value also to find the column index.

To find record with text:
For row = 1 To objPBDW.RowCount
      If objPBDW.GetCellData(row, col) = strData Then
          Exit For
      End If
Next
Accept as solution/Give Kudos to the author if the piece of information answered/helped you to solve your problem.
All the thoughts here are mine not related to my employer nor anyone.
Test Automation Ecstasy

View solution in original post

0 Likes
Absent Member.
Absent Member.

Shanmugavel,

 

Tried your method - below is what I wrote up:

 

For row = 1 to PbWindow("lems"). PbWindow("elect").PbDataWindow("select").RowCount

If PbWindow("lems"). PbWindow("elect").PbDataWindow("select").GetCellData (row,col) = "GEBERTS" Then

Exit For

End If

Next

 

It runs and local variables show:

 

Name                                    Value                                    Type Name

Row                                       23                                           Long

Col                                          Empty                                   User-defined Type

 

In my datawindow, I have a column named Code. I’m attempting to locate the cell in that Code column that says GEBRTS, then have the script activate that cell for me. Forgive my newness, trying to give what info I can.

 

Thanks!

0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

assign value to variant col. See your table and assign the column no.

Accept as solution/Give Kudos to the author if the piece of information answered/helped you to solve your problem.
All the thoughts here are mine not related to my employer nor anyone.
Test Automation Ecstasy
0 Likes
Absent Member.
Absent Member.

okay - so added col=1 to the mix

 

so basically it searches until it finds my GEBRTS, then just moves on and my attempts to Activate that cell after it's found have failed - what would I need to add to the code in order to activate this cell after the search finds it.

 

Thanks again!

0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

Once you found that row, your row and col values are there. then you need to use ActivateCell(row, col) or SelectCell(row, col)

 

I just gave you the sample to find the row, that's all.

Accept as solution/Give Kudos to the author if the piece of information answered/helped you to solve your problem.
All the thoughts here are mine not related to my employer nor anyone.
Test Automation Ecstasy
0 Likes
Absent Member.
Absent Member.

Great thank you!

 

My code is now:

 

col = 1

for row = 1 to PbWindow("lems"). PbWindow("elect").PbDataWindow("select").RowCount

If PbWindow("lems"). PbWindow("elect").PbDataWindow("select").GetCellData (row,col) = "GEBERTS" Then

PbWindow("lems"). PbWindow("elect").PbDataWindow("select").ActivateCell (row,col)

Exit For

End If

Next

 

 

It's throwing a syntax error telling me that "you cannot use parentheses when calling a sub"

0 Likes
Absent Member.
Absent Member.

Never mind - fumbled around a bit but got it going - thank you both so much!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.