FindRequired method (DataWindows)
Description
Reports the next row and column that is required and contains
a null value. The method arguments that specify where to start searching
also store the results of the search. You can speed up the search
by specifying that FindRequired check only inserted
and modified rows.
Controls
DataWindow type |
Method applies to |
---|---|
PowerBuilder |
DataWindow control, DataStore object |
Web ActiveX |
DataWindow control |
Syntax
[PowerBuilder]
1 |
integer <span>dwcontrol</span><span>.</span><span>FindRequired</span> ( DWBuffer <span>dwbuffer</span>, long <span>row</span>, integer <span>colnbr</span>, string <span>colname</span>, boolean <span>updateonly</span> ) |
[Web ActiveX]
1 |
number <span>dwcontrol</span><span>.Find</span>Required ( number <span>dwbuffer</span>, number <span>row</span>, number <span>colnbr</span>, string <span>colname</span>, boolean <span>updateonly</span> ) |
Argument |
Description |
---|---|
dwcontrol |
A reference to the DataWindow control |
dwbuffer |
A value indicating the DataWindow buffer
|
row |
A value identifying the first row to PowerBuilder The row argument must be a variable so |
colnbr |
A value identifying the first column PowerBuilder The colnbr argument must be a variable |
colname |
A string in which you want to store the PowerBuilder The colname argument must be a variable |
updateonly |
A value indicating whether you want to
|
Return Values
Returns 1 if FindRequired successfully
checked the rows and –1 if an error occurs.
If any argument’s value is null, in PowerBuilder
and JavaScript the method returns null.
Usage
For FindRequired to report an empty required
column, the column’s value must actually be null, not an
empty string.
To make a column required, set the Required property to true
in a script or check the Required check box for the column in the
DataWindow painter.
New rows have null values in their columns, unless the columns
have default values. If updateonly is false, FindRequired reports
empty required columns in new rows. If updateonly is
true, FindRequired does not check new rows because
new, empty rows are not updated in the database.
When the user modifies a row and leaves a column empty, the
new value is an empty string, unless the column’s edit
style has the Empty String Is null check box checked. FindRequired does
not report empty required columns in modified rows unless this property
is set.
Examples
The following code makes a list of all the row numbers
and column names in dw_1 in which required columns are
missing values. The list is displayed in the MultiLineEdit mle_required:
1 |
long ll_row = 1 |
1 |
integer colnbr = 0 |
1 |
string colname |
1 |
1 |
mle_required.Text = "" |
1 |
DO WHILE ll_row <> 0 |
1 |
colnbr++ // Continue searching at next column |
1 |
// If there's an error, exit |
1 |
IF dw_1.<span>FindRequired</span>(Primary!, & |
1 |
ll_row, colnbr, & |
1 |
colname, false) < 0 THEN EXIT |
1 |
1 |
// If a row was found, save the row and column |
1 |
IF ll_row <> 0 THEN |
1 |
mle_required.Text = mle_required.Text & |
1 |
+ String(ll_row) + "~t" & |
1 |
+ colname + "~r~n" |
1 |
END IF |
1 |
1 |
// When FindRequired returns 0 (meaning |
1 |
// no more rows found), drop out of loop |
1 |
LOOP |
This example is a function that ensures that no required
column in a DataWindow control is empty (contains null). It takes
one argument—the DataWindow control, which is declared
in the function declaration like this:
1 |
DataWindow adw_control |
The function returns –2 if the user’s last
entry cannot be accepted or if FindRequired returns
an error. It returns –1 if an empty required column is found.
It returns 1 if all required columns have data:
1 |
integer li_colnbr = 1 |
1 |
long ll_row = 1 |
1 |
string ls_colname, ls_textname |
1 |
1 |
// Make sure the last entry is accepted |
1 |
IF adw_control.AcceptText() = -1 THEN |
1 |
adw_control.SetFocus() |
1 |
RETURN -2 |
1 |
END IF |
1 |
1 |
// Find the first empty row and column, if any |
1 |
IF adw_control.<span>FindRequired</span>(Primary!, ll_row, & |
1 |
li_colnbr, ls_colname, true) < 1 THEN |
1 |
//If search fails due to error, then return |
1 |
RETURN -2 |
1 |
END IF |
1 |
1 |
// Was any row found? |
1 |
IF ll_row <> 0 THEN |
1 |
// Get the text of that column's label. |
1 |
ls_textname = ls_colname + "_t.Text" |
1 |
ls_colname = adw_control.Describe(ls_textname) |
1 |
1 |
// Tell the user which column to fill in |
1 |
MessageBox("Required Value Missing", & |
1 |
"Please enter a value for '" & |
1 |
+ ls_colname + "', row " & |
1 |
+ String(ll_row) + ".", & |
1 |
StopSign! ) |
1 |
1 |
// Make the problem column current. |
1 |
adw_control.SetColumn(li_colnbr) |
1 |
adw_control.ScrollToRow(ll_row) |
1 |
adw_control.SetFocus() |
1 |
RETURN -1 |
1 |
END IF |
1 |
1 |
// Return success code if all required |
1 |
// rows and columns have data |
1 |
RETURN 1 |