Variable Management Functions

Variable Management

FieldBlock Return a code block that sets/gets a value for a given field
FieldWBlock Return a sets/gets code block for field in a given work area
HB_AParams Returns an array containing values of all parameters passed to a function, method or procedure
HB_ArgC Returns the number of command line arguments
HB_ArgCheck Checks existence of an internal switch on the command line
HB_ArgShift Updates HB_Arg* parameter list removing the 1-st one and replacing it by others
HB_ArgString Retrieves the vale of an internal switch set on the command line.
HB_ArgV Retrieves the value of a command line argument
HB_PIsByRef Determine if a parameter is passed by reference.
HB_PValue Retrieves the value of an argument.
HB_ValToStr Converts any scalar type to a string.
MemVarBlock Returns a codeblock that sets/gets a value of memvar variable
PCount Retrieves the number of arguments passed to a function.
Type Retrieves the type of an expression
ValType Retrieves the data type of an expression

MemVarBlock()

MEMVARBLOCK()

Returns a codeblock that sets/gets a value of memvar variable

Syntax

      MEMVARBLOCK( <cMemvarName> ) --> <bBlock>

Arguments

<cMemvarName> – a string that contains the name of variable

Returns

<bBlock> a codeblock that sets/get the value of variable

Description

This function returns a codeblock that sets/gets the value of PRIVATE or PUBLIC variable. When this codeblock is evaluated without any parameters passed then it returns the current value of given variable. If the second parameter is passed for the codeblock evaluation then its value is used to set the new value of given variable – the passed value is also returned as a value of the codeblock evaluation.

Examples

      PROCEDURE Main()
         LOCAL cbSetGet
         PUBLIC xPublic

         cbSetGet := MEMVARBLOCK( "xPublic" )
         EVAL( cbSetGet, "new value" )
         ? "Value of xPublic variable", EVAL( cbSetGet )

         RETURN

Compliance

Clipper

Seealso

__MVGET(), __MVPUT()

Files

Library is rtl

FieldWBlock()

FIELDWBLOCK()

Return a sets/gets code block for field in a given work area

Syntax

      FIELDWBLOCK( <cFieldName>, <nWorkArea> ) --> bFieldBlock

Arguments

<cFieldName> is a string that contain the field name.

<nWorkArea> is the work area number in which <cFieldName> exist.

Returns

FIELDWBLOCK() return a code block that when evaluate could retrieve field value or assigning a new value for a field in a given work area. If <cFieldName> is not specified or from type other than character, or if <nWorkArea> is not specified or is not numeric FIELDWBLOCK() return NIL.

Description

FIELDWBLOCK() return a code block that sets/gets the value of field from a given work area. When this code block is evaluated without any parameters passed then it returns the current value of the given field. If the code block is evaluated with a parameter, than its value is used to set a new value to the field, this value is also return by the block. If the block is evaluate and there is no field with the name <cFieldName> in work area number <nWorkArea>, the code block return NIL.

Examples

      LOCAL bField
      // this block work on the field "name" that exist on work area 2
      bFiled := FIELDBLOCK( "name", 2 )
      // open a file named One in work area 1
      // that have a field named "name"
      SELECT 1
      USE one
      // open a file named Two in work area 2
      // it also have a field named "name"
      SELECT 2
      USE two
      SELECT 1
      ? "Original names: ", One->name, Two->name
      ? "Name value for file Two :", EVAL( bField )
      EVAL( bField, "Two has new name" )
      ? "and now: ", One->name, Two->name

Compliance

If the block is evaluate and there is no field with the name <cFieldName> in the given work area, the code block return NIL.

CA-Cl*pper would raise BASE/1003 error if the field does not exist.

Files

Library is rtl

Seealso

EVAL(), FIELDBLOCK(), MEMVARBLOCK()

FieldBlock()

FIELDBLOCK()

Return a code block that sets/gets a value for a given field

Syntax

      FIELDBLOCK( <cFieldName> ) --> bFieldBlock

Arguments

<cFieldName> is a string that contain the field name.

Returns

FIELDBLOCK() return a code block that when evaluate could retrieve a field value or assigning a new value to the field. If <cFieldName> is not specified or from type other than character, FIELDBLOCK() return NIL.

Description

FIELDBLOCK() return a code block that sets/gets the value of field. When this code block is evaluated without any parameters passed then it returns the current value of the given field. If the code block is evaluated with a parameter, than its value is used to set a new value to the field, this value is also return by the block. If the block is evaluate and there is no field with the name <cFieldName> in the current work area, the code block return NIL.

Note that FIELDBLOCK() works on the current work area, if you need a specific work area code block use FIELDWBLOCK() instead.

Examples

      // open a file named Test that have a field named "name"
      LOCAL bField
      bFiled := FIELDBLOCK( "name" )
      USE Test
      ? "Original value of field 'name' :", EVAL( bField )
      EVAL( bField, "Mr X new name" )
      ? "New value for the field 'name' :", EVAL( bField )

Compliance

If the block is evaluate and there is no field with the name <cFieldName> in the current work area, the code block return NIL.

CA-Cl*pper would raise BASE/1003 error if the field does not exist.

Files

Library is rtl

Seealso

EVAL(), FIELDWBLOCK(), MEMVARBLOCK()

C5_MEMVARBLOCK

 MEMVARBLOCK()
 Return a set-get code block for a given memory variable
------------------------------------------------------------------------------
 Syntax

     MEMVARBLOCK(<cMemvarName>) --> bMemvarBlock

 Arguments

     <cMemvarName> is the name of the variable referred to by the set-get
     block, specified as a character string.

 Returns

     MEMVARBLOCK() returns a code block that when evaluated sets (assigns) or
     gets (retrieves) the value of the given memory variable.  If
     <cMemvarName> does not exist, MEMVARBLOCK() returns NIL.

 Description

     The code block created by MEMVARBLOCK() has two operations depending on
     whether an argument is passed to the code block when it is evaluated.
     If evaluated with an argument, it assigns the value of the argument to
     <cMemvarName>.  If evaluated without an argument, the code block
     retrieves the value of <cMemvarName>.

 Notes

     .  MEMVARBLOCK() creates set-get blocks only for variables whose
        names are known at runtime.  MEMVARBLOCK(), therefore, cannot be used
        to create set-get blocks for local or static variables.  The same
        restriction applies to creating blocks using the macro operator (&).

 Examples

     .  This example compares MEMVARBLOCK() to a code block created
        using the macro operator (&).  Note that using MEMVARBLOCK() allows
        you to avoid the speed and size overhead of the macro operator:

        PRIVATE var := "This is a string"
        //
        // Set-Get block defined using macro operator
        bSetGet := &( "{ |setVal|;
              IF( setVal == NIL, var, var := setVal ) }" )
        // Set-Get block defined using MEMVARBLOCK()

        // bSetGet created here is the functional
        // equivalent of bSetGet above
        bSetGet := MEMVARBLOCK("var")

 Files   Library is CLIPPER.LIB.

See Also: FIELDBLOCK() FIELDWBLOCK()

 

C5 Variable Handling Commands

ACCEPT :

Place keyboard input into a memory variable

ACCEPT [<expPrompt>] TO <idVar>

CLEAR ALL* :

Close files and release public and private variables

CLEAR ALL

CLEAR MEMORY :

Release all public and private variables

CLEAR MEMORY

DECLARE* :

Create and initialize private memory variables and arrays

DECLARE <identifier> [[:= <initializer>], ... ]

FIELD :

Declare database field names

FIELD <idField list> [IN <idAlias>]

INPUT :

Enter the result of an expression into a variable

INPUT [<expPrompt>] TO <idVar>

LOCAL :

Declare and initialize local variables and arrays

LOCAL <identifier> [[:= <initializer>], ... ]

MEMVAR :

Declare private and public variable names

MEMVAR <idMemvar list>

MEMVARBLOCK() :

Return a set-get code block for a given memory variable

MEMVARBLOCK(<cMemvarName>) --> bMemvarBlock

PARAMETERS :

Create private parameter variables

PARAMETERS <idPrivate list>

PRIVATE :

Create and initialize private memory variables and arrays

PRIVATE <identifier> [[:= <initializer>], ... ]

PUBLIC :

Create and initialize public memory variables and arrays

PUBLIC <identifier> [[:= <initializer>], ... ]

RELEASE :

Delete public and private memory variables

RELEASE <idMemvar list>
RELEASE ALL [LIKE | EXCEPT <skeleton>]

RESTORE :

Retrieve memory variables from a memory (.mem) file

RESTORE FROM <xcMemFile> [ADDITIVE]

SAVE :

Save variables to a memory (.mem) file

SAVE TO <xcMemFile> [ALL [LIKE | EXCEPT <skeleton>]]

STATIC :

Declare and initialize static variables and arrays

STATIC <identifier> [[:= <initializer>], ... ]

STORE* :

Assign a value to one or more variables

STORE <exp> TO <idVar list>
<idVar> = <exp>
<idVar> := [ <idVar2> := ...] <exp>