xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

DEFAULT TO

Assigns a default value to a NIL argument.

Syntax

DEFAULT <varName1> TO <xValue1> ;
     [, <varNameN> TO <xValueN> ]

Arguments

<xValue>
This is an expression whose value is assigned to <varName> when the variable contains NIL.
<varName>
The symbolic names of the variable to assign a default value to.

Description

The DEFAULT TO command assigns the value of <xValue> to the variable <varName> when <varName> contains NIL. Multiple variables can be assigned default values by separating a list of TO options with commas.

The command is used in functions and procedures that accept optional arguments. Optional arguments receive NIL as value and are assigned default values using DEFAULT TO.

Info

See also::=, Default(), PValue(), IF, STORE, Valtype()
Category: Memory commands
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example shows a function that normalizes strings in
// length and capitilization.

   FUNCTION Normalize( cStr, nPad )

       DEFAULT cString TO "" , ;
               nPad    TO Len(cStr)

   RETURN PadR( Upper( cStr[1] ) + Lower( SubStr( cStr, 2 ), nPad )

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe