Field Default Options Property

The Field Default options buttons let you choose whether a field has a default value, and if the field does have a default value, the option buttons let you choose how the default button is determined, as follows:

·       Code: If you select the Code option button, you enter code on the Edit page’s Code sub-page that returns the field’s default value. See below for more detail.

·       Generate Sequential or Generate GUID: If you select either the Generate Sequential or the Generate GUID default option buttons, you are asking VPME to use one of its generation routines to generate default values for the field. The Generate Sequential and Generate GUID options are used primarily to generate primary key values for a primary key, but they can be used for any field where you find it appropriate. See Generating Surrogate Primary Keys to learn more about the Generate Sequential and Generate GUID options.

Code Default Option

When you select the Code default option, you must then select the Code sub-page of the Edit page to enter code that will return the default values that you want. The default value that your code returns will be automatically entered into a field when a user adds a record to a table, view or CursorAdapter.

Ø To enter Default Value Code for a Field

1.   Make the field the currently selected field on the Data Builder Edit page.

2.   On the Properties page, click the Code option in the Default box.

3.   Click the Code page.

4.   On the Code page, check the Default check box. VPME displays the Default Code entry window.

 

5.   Leave the line that begins with “LPARAMETERS” in place and add your code after it. In the simple example shown in the above graphic, the code is returning a character literal string as the default value.

Default Code Tips

The purpose of the Default Code is to return a value. Here are the rules that determine what happens when your code returns a value:

·       If the field is of logical type, the value that is returned is placed in the field.

·       If the field is not of logical type, returning a logical value (.T. or .F.) cancels the adding or copying of a record.

·       If the field is not of logical type and a logical value is not returned, the value that is returned is placed into the field.

If all you want to do is return a simple literal default value, the literal value you enter must take into account the field type:

·       Character Fields: Enclose a character string in single or double quotes.

·       Numeric Fields: Enter a numeric value directly without quotes.

·       Date Fields: Enclose a date string in braces. For example, {01/01/96}.

If you enter code that determines a variable default value, the default value returned must take into account the field type.

View Tip: When a record is added to a view, if the Default Option property is “Off” for a view field whose source table field is a primary key field in the source table, a check is made to see if a Default Option property other than “Off” has been selected for the primary key source field. If so, the Default option selected is evaluated to produce a default primary key value for the view field.

Default Code Parameters

The parameters passed to to the Default Code are described below along with tips for using the parameters.

·       stcRulesID: Passes the cRulesID form property value. You can use the cRulesID form property to store a value that is passed to your record-level code.

·       For example, if your Default Code needed to know, say, the current application user’s Status, you can store the user’s status in the cRulesID form property and it will be passed to your code. For the user properties available to you, see Error! Reference source not found..

·       stoCallingObject: Passes the object reference of the data handling object. You can use this object reference to access the methods of the data handling object in your code.

·       For example, to access the OpenTable method of the data handler, your code could use the method call  “stoCallingObject.OpenTable(parameters)” where “parameters” is the parameters list expected by the OpenTable method. See the Data Handler Class chapter in the VPME 9.1 Technical Reference manual to learn about the data handler methods available to you.

More:

Field Default - PreSave Property