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.
Applies to
|
DataWindow type |
Method applies to |
|---|---|
|
PowerBuilder |
DataWindow control, DataStore object |
Syntax
PowerBuilder
|
1 |
integer dwcontrol.FindRequired ( DWBuffer dwbuffer, long row, integer colnbr, string colname, boolean updateonly ) |
|
Argument |
Description |
|---|---|
|
dwcontrol |
A reference to the DataWindow control or DataStore in |
|
dwbuffer |
A value indicating the DataWindow buffer you want to
|
|
row |
A value identifying the first row to be searched. Row PowerBuilder The row argument |
|
colnbr |
A value identifying the first column to be searched. PowerBuilder The colnbr argument |
|
colname |
A string in which you want to store the name of the PowerBuilder The colname argument |
|
updateonly |
A value indicating whether you want to validate all
|
Return value
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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
long ll_row = 1 integer colnbr = 0 string colname mle_required.Text = "" DO WHILE ll_row <> 0 colnbr++ // Continue searching at next column // If there's an error, exit IF dw_1.FindRequired(Primary!, & ll_row, colnbr, & colname, false) < 0 THEN EXIT // If a row was found, save the row and column IF ll_row <> 0 THEN mle_required.Text = mle_required.Text & + String(ll_row) + "~t" & + colname + "~r~n" END IF // When FindRequired returns 0 (meaning // no more rows found), drop out of loop 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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
integer li_colnbr = 1 long ll_row = 1 string ls_colname, ls_textname // Make sure the last entry is accepted IF adw_control.AcceptText() = -1 THEN adw_control.SetFocus() RETURN -2 END IF // Find the first empty row and column, if any IF adw_control.FindRequired(Primary!, ll_row, & li_colnbr, ls_colname, true) < 1 THEN //If search fails due to error, then return RETURN -2 END IF // Was any row found? IF ll_row <> 0 THEN // Get the text of that column's label. ls_textname = ls_colname + "_t.Text" ls_colname = adw_control.Describe(ls_textname) // Tell the user which column to fill in MessageBox("Required Value Missing", & "Please enter a value for '" & + ls_colname + "', row " & + String(ll_row) + ".", & StopSign! ) // Make the problem column current. adw_control.SetColumn(li_colnbr) adw_control.ScrollToRow(ll_row) adw_control.SetFocus() RETURN -1 END IF // Return success code if all required // rows and columns have data RETURN 1 |
See also