Find – PB Docs 150

Find method (DataWindows)


Finds the next row in a DataWindow or DataStore in which data
meets a specified condition.


DataWindow type

Method applies to


DataWindow control, DataWindowChild object, DataStore


Server component

Web ActiveX

DataWindow control, DataWindowChild object


[PowerBuilder and Web DataWindow server component]

[Web DataWindow and Web ActiveX]




A reference to the DataWindow control,
DataStore, or child DataWindow in which you want to search the detail


A string whose value is a boolean expression
that you want to use as the search criterion. The expression includes
column names.


A value identifying the row location
at which to begin the search. Start can be
greater than the number of rows.


A value identifying the row location
at which to end the search. End can be greater
than the number of rows. To search backward, make end less
than start.

Return Values

Returns the number of the first row that meets the search
criteria within the search range. Returns 0 if no rows are found
and one of these negative numbers if an error occurs:

  • –1 General

  • –5 Bad argument

If any argument’s value is null, in PowerBuilder
and JavaScript the method returns null.


note.png PowerBuilder environment

For use with a RichTextEdit control or presentation style,
see Find in the PowerScript Reference.

The search is case sensitive. When you compare text to a value
in a column, the case must match.

When the Find expression includes quotes

If the text you want to find includes quotes, you must treat
the nested quote as doubly nested, because the DataWindow parses
the string twice before the Find method uses
it. Therefore, you cannot simply alternate double and single quotes, as
you can in most strings.

For example, to find the name O’Connor, the Find
expression can be:

"O~~~'Connor" (3
tildes and single quote) or
"O~~~~~"Connor" (5
tildes and double quote)

but not:

"O'Connor" or "O~"OConnor"

When the last row satisfies the search criteria

If you use Find in a loop that searches
through all rows, you may end up with an endless loop if the last
row satisfies the search criteria. When the start value
becomes greater than end, the search reverses
direction and Find would always succeed, resulting in an endless

To solve this problem, you could make the end value
1 greater than the number of rows (see the examples). Another approach,
shown below, would be to test within the loop whether the current
row is greater than the row count and, if so, exit. This PowerBuilder
code illustrates how:


This statement searches for the first row in dw_status
in which the value of the emp_salary column is greater
than 100,000. The search begins in row 3 and continues until it
reaches the last row in dw_status:

To test values in more than one column, use boolean
operators to join conditional expressions. The following statement
searches for the employee named Smith whose salary exceeds 100,000:

These statements search for the first row in dw_emp
that matches the value that a user entered in the SingleLineEdit
called Name (note the single quotes embedded in the search expression
around the name):

This script excerpt finds the first row that has
a null value in emp_id. If no null is found, the script
updates the DataWindow object. If a null is found, it displays a

The following script attached to a Find Next command
button searches for the next row that meets the specified criteria
and scrolls to that row. Each time the button is clicked, the number
of the found row is stored in the instance variable il_found.
The next time the user clicks Find Next, the search continues from
the following row. When the search reaches the end, a message tells
the user that no row was found. The next search begins again at
the first row.

Note that although the search criteria are hard-coded here,
a more realistic scenario would include a Find button that prompts
the user for search criteria. You could store the criteria in an
instance variable, which Find Next could use:

This example searches all the rows in dw_main
and builds a list of the names that include a lowercase a. Note
that the end value of the search is one greater than the row count,
avoiding an infinite loop if the name in the last row satisfies
the search:

See Also

Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x