CT_FIELDTYPE

 FIELDTYPE()
 Determines the data type for a field

 Syntax

     FIELDTYPE(<nField>) --> cType

 Argument

     <nField>  Designates the data field for which the data type is
     determined.

 Returns

     FIELDTYPE() returns a single character that designates the data type of
     the data field (assuming the data field number is valid).  FIELDTYPE()
     returns the following characters for the various data field types:

     Table 10-1: Coding for Data Field Types
     ------------------------------------------------------------------------
     Character    Data Type
     ------------------------------------------------------------------------
     C            Character string
     N            Numeric
     D            Date
     L            Logical
     M            MEMO
     ------------------------------------------------------------------------

 Description

     FIELDTYPE() operates in a similar fashion to the CA-Clipper TYPE()
     function.  With TYPE(), you must always know only the name of the data
     field.  However, FIELDTYPE() requires that you only know the data field,
     not its name.  Use the function to confirm data types for data fields
     when a program is working with different databases that have different
     field names.

 Note

     .  If there are  invalid data field numbers, the function returns
        a null string.

 Example

     Data type for field number 5:

     IF FIELDTYPE(5) = "C"
        ? "Field No. 5 is a character field!"
     ENDIF

See Also: FCOUNT, FIELDNUM, FIELDNAME,  FIELDSIZE, FIELDDECI,  DBF Structure



CT_FIELDSIZE

FIELDSIZE()
 Determines the size of a field
------------------------------------------------------------------------------
 Syntax

     FIELDSIZE(<nField>) --> nLength

 Argument

     <nField>  Designates the number of the field to evaluate.

 Returns

     FIELDSIZE() returns a numeric value that corresponds to the field length
     of a valid field number.

 Description

     Use FIELDSIZE() to determine the length (or size) of data field of
     desired data types.  This determines the window width needed for output
     to appear without a line break, or the length needed for an input to
     automatically fit in the database.

 Note

     .  If there is an invalid data field number, the function returns
        a value of 0.

 Example

     Determine the total length of fields 3 to 5:

     nLength  :=  0
     FOR I = 3 TO 5
        nLength := nLength + FIELDSIZE()
     NEXT

See Also:  FCOUNT, FIELDNUM, FIELDNAME, FIELDTYPE, FIELDDECI, PAD, STR, DBF Structure

CT_FIELDNUM

FIELDNUM()
 Determines the field number for a specific field in a database file
------------------------------------------------------------------------------
 Syntax

     FIELDNUM(<cFieldName>) --> nFieldNumber

 Argument

     <cFieldName>  Designates to the field name.

 Returns

     FIELDNUM() returns the number of the data field.

 Description

     FIELDNUM() is the exact opposite of the CA-Clipper FIELD() function.
     Use this function when you need a data field number instead of the data
     field name.  FIELDNUM() determines if a symbol name pertains to a data
     field or a memory variable (see Examples).

 Note

     .  If a data field with the name <cFieldName> is not available,
        the function returns a value of 0.

 Example

     Is it a field or a variable?

     IF FIELDNUM("cName") > 0.
        REPLACE cName WITH UPPER(cName).
     ELSE.
        cName  :=  UPPER(cName).
     ENDIF

See Also:  FCOUNT,  FIELDNAME, FIELDTYPE, FIELDSIZE, FIELDDECI, PAD, STR, DBF Structure

 

DBF Structure

How I can obtain structure info of a DBF ?

 

PROC MAIN()
 
   SETMODE( 25, 80 )
   CLS
 
   USE ..\datas\TEST1
? "No Field Name T Size Dec"
   ? "-- ------------ - ----- ---"
 
   FOR nFld := 1 TO FCOUNT()
       * or : FIELDNUM( FIELDNAME( nFld ) 
       ? STR( nFld, 2, 0 ),; // CT Database Function
         PAD( FIELDNAME( nFld ), 12 ),; // Standard dBASE function
         FIELDTYPE( nFld ),; // CT Database Function
         STR( FIELDSIZE( nFld ), 5, 0 ),; // CT Database Function
         STR( FIELDDECI( nFld ), 3, 0 ) // CT Database Function
    NEXT nFld
 
    ? 
    WAIT "EOF DBF_Struct.prg"
 
RETURN // MAIN.DBF_Struct.prg"

CT_FIELDDECI

FIELDDECI()
 Determines the number of decimal places in a field
------------------------------------------------------------------------------
 Syntax

     FIELDDECI(<nField>) --> nDecimalPlaces

 Argument

     <nField>  Designates for which numeric data field to determine the
     number of decimal places.

 Returns

     When a field number is valid, FIELDDECI() returns the number of decimal
     places in a numeric data field.

 Description

     It is important to know how many decimal places are in a data field so
     you can limit the input of significant digits in the corresponding
     number.  FIELDDECI() determines the number of decimal places available.
     This allows you to tailor inputs to the database without changing the
     program.

 Note

     .  If you have an invalid field number, the function returns a
        value of 0.

 Example

     Convert the second field to a string with the correct number of decimal
     places:

     @ 0, 60 SAY "Price:  " + STR(cField2, 8, FIELDDECI(2))

See Also: FCOUNT, FIELDNUM, FIELDNAME, FIELDTYPE, FIELDSIZE, DBF Structure

-> Alias assignment

->
 Alias assignment--binary                        (Special)
------------------------------------------------------------------------------
 Syntax

     <idAlias>-><idField>
     <idAlias>->(<exp>)
     (<nWorkArea>)-><idField>
     (<nWorkArea>)->(<exp>)
     FIELD-><idVar>
     MEMVAR-><idVar>

 Operands

     <idAlias> is the name of the unselected work area to access and must
     refer to a work area with a database file in USE.

     <nWorkArea> is the number of the unselected work area to access.

     <idField> is the name of a field in the specified work area.

     <exp> is an expression of any data type to be executed in the
     specified work area.  If an expression more complicated than a single
     field reference is used as the second operand, the expression must be
     enclosed in parentheses ( ).

     <idVar> is any valid CA-Clipper identifier.  Depending on whether
     you specify FIELD or MEMVAR, the identifier will be forced to a database
     field or memory variable (public or private) reference.

 Description

 When used with an <idAlias> as the first operand, the alias operator

     (->) accesses field information or evaluates an expression in the
     indicated work area.  The alias operator implicitly SELECTs the
     <idAlias> before evaluating the <idField> or <exp> operand.  When the
     evaluation is complete, the original work area is SELECTed again.  An
     alias reference can be in an expression or on a line by itself:

     ? Customer->Name
     Customer->(UpdateTransaction())

     Using the alias operator lets you:

     .  Access information from unselected work areas within
        expressions

     .  Access environmental information from unselected work areas

     .  Access information from unselected work areas in modes such as
        REPORT and LABEL FORMs

     .  Write more compact code

     In addition to allowing expression and field evaluation in unselected
     work areas, the alias operator makes an explicit reference to a field or
     variable using either the FIELD or the MEMVAR keyword aliases.  MEMVAR
     forces <idVar> to refer to a memory variable name, and FIELD forces it
     to reference a database field.  These special alias identifiers allow
     you to avoid ambiguity when there are conflicts between field and memory
     variable names.  Remember that a reference to a variable identifier not
     prefaced with an alias defaults to a field if there are both field and
     memory variables with the same name.  To override this, use the (/V)
     option when compiling.

     In addition to specifying the alias as an identifier, you can access the
     target work area using an expression that returns the work area number
     if the expression is enclosed by parentheses.  This lets you use work
     area numbers as handles, which is useful for passing references to work
     areas without using macros, aliases, names, etc.

 Examples

     .  This example accesses database and work area information in an
        unselected work area:

        USE Customer NEW
        USE Invoices NEW
        ? Customer->CustName                  // Result: Bill Smith
        ? Customer->(RECNO())                 // Result: 1
        ? Customer->(FOUND())                 // Result: .F.
        ? Customer->(City + ", " + State + ;
           "  " + Zip)                        // Result: ShadowVille,
                                              //         CA  90415

     .  This example uses a user-defined function (MySeek()) as an
        operand of the alias operator for a common operation that normally
        requires many more statements:

        IF Invoices->(MySeek(CustNum))
           <process customer>...
        ELSE
           <process no find>...
        ENDIF
        RETURN

        FUNCTION MySeek( cSearch )
           SEEK cSearch
        RETURN (FOUND())

        Note:  This example is just an illustration of the alias operator
        with a user-defined function.  CA-Clipper's DBSEEK() could be used
        instead of MySeek().

     .  This example explicitly references field and memory variables
        with the same name:

        USE Customer NEW
        MEMVAR->CustName = "Bill Smith"      // Create a memvar
                                             // CustName
        LOCATE FOR MEMVAR->CustName = FIELD->CustName

     .  This example uses an expression as a work area handle to
        create a work area-independent database operation:

        cTable1 := "C:Myfile.dbf"
        cTable2 := "D:Myfile.dbf"
        USE (cTable1) NEW
        hArea1 = SELECT()
        USE (cTable2) NEW
        hArea2 = SELECT()
        DoStuff( hArea1, hArea2 )

        FUNCTION DoStuff( hArea1, hArea2 )
           LOCAL nCount, nSave
           nSave := SELECT()
           SELECT (hArea1)
           FOR nCount := 1 TO FCOUNT()
              FIELDPUT( nCount, ( hArea2 )-> ;
                 ( FIELDGET( nCount )))
           NEXT
           SELECT (nSave)
           RETURN NIL

See Also: FIELD FIELDNAME() FIELDPOS() FIELDGET() SELECT

TBrowse & TBColumn basics

TBrowse and TBColumn basics (.pdf)

Working version of sample program in this article.

 

TBr_Bass

C5 Database Functions

AFIELDS() :

Fill arrays with the structure of the current database file

AFIELDS([<aFieldNames>],
    [<aTypes>],
    [<aWidths>],
    [<aDecimals>]) --> nFields

ALIAS() : 

Return a specified work area alias

ALIAS([<nWorkArea>]) --> cAlias

BOF() : 

Determine when beginning of file is encountered

BOF() --> lBoundary

DBAPPEND() : 

Add a new record

DBAPPEND() --> NIL

DBCLEARFILTER() : 

Clear a filter condition

    DBCLEARFILTER() –> NIL

DBCLEARIND() :  Close all indexes for the current work area

    DBCLEARINDEX() --> NIL

DBCLEARREL() : 

Clear active relations

DBCLEARRELATION() --> NIL

DBCLOSEALL() : 

Close all occupied workareas

DBCLOSEALL() --> NIL

DBCLOSEAREA() : 

Close a workarea

DBCLOSEAREA() --> NIL

DBCOMMIT() : 

Flush pending updates

DBCOMMIT() --> NIL

DBCOMMITALL() : 

Flush pending updates in all workareas

DBCOMMITALL() --> NIL

DBCREATE() : 

Create a database file from a database structure array

DBCREATE(<cDatabase>, <aStruct> [, <cDriver> ] ) --> NIL

DBCREATEIND() : 

Create an Index

   DBCREATEINDEX(<cIndexName>, <cKeyExpr>,
        [<bKeyExpr>], [<lUnique>]) --> NIL

DBDELETE() : 

Mark a record for deletion

DBDELETE() --> NIL

DBEDIT() : 

        Browse records in a table layout

    DBEDIT([<nTop>], [<nLeft>],
        [<nBottom>], <nRight>],
        [<acColumns>],
        [<cUserFunction>],
        [<acColumnSayPictures> | <cColumnSayPicture>],
        [<acColumnHeaders> | <cColumnHeader>],
        [<acHeadingSeparators> | <cHeadingSeparator>],
        [<acColumnSeparators> | <cColumnSeparator>],
        [<acFootingSeparators> | <cFootingSeparator>],
        [<acColumnFootings> | <cColumnFooting>]) --> NIL

DBEVAL() : 

Evaluate a code block for each record

DBEVAL(<bBlock>,
    [<bForCondition>],
    [<bWhileCondition>],
    [<nNextRecords>],
    [<nRecord>],
    [<lRest>]) --> NIL

DBF()* : 

Return current alias name

DBF() --> cAlias

DBFIELDINFO() : 

Return and optionally change information about a field

   DBFIELDINFO(<nInfoType>,

        <nFieldPos>,
        [<expNewSetting>]) --> uCurrentSetting

DBFILEGET() : 

Insert the contents of a field into a file

     DBFILEGET(<nFieldPos>, <cTargetFile>, <nMode>)
        --> lSuccess

DBFILEPUT() : 

Insert the contents of a file into a field

     DBFILEPUT(<nFieldPos>, <cSourceFile>)
        --> lSuccess

 DBFILTER() : 

Return the current filter expression as a character string

DBFILTER() --> cFilter

DBGOBOTTOM() : 

Move to the last logical record

DBGOBOTTOM() --> NIL

DBGOTO() : 

Move to a particular record

DBGOTO(<nRecordNumber>) --> NIL

DBGOTOP() : 

Move to the first logical record

DBGOTOP() --> NIL

DBINFO() : 

         Return and optionally change database file information

    DBINFO(<nInfoType>, [<expNewSetting>])
        --> uCurrentSetting

DBORDERINFO() :          Return and optionally change information about orders and index files

    DBORDERINFO(<nInfoType>,   [<cIndexFile>],
        [<cOrder> | <nPosition>],
        [<expNewSetting>]) --> uCurrentSetting

DBRECALL() : 

Reinstate a record marked for deletion

DBRECALL() --> NIL

DBRECORDINFO() :

         Return and optionally change information about a record

    DBRECORDINFO(<nInfoType>,
        [<nRecord>],
        [<expNewSetting>]) --> uCurrentSetting

DBREINDEX() :

         Recreate all active indexes for the current work area

    DBREINDEX() --> NIL

DBRELATION() :

Return the linking expression of a specified relation

DBRELATION( <nRelation> ) --> cLinkExp

DBRLOCK() :      

         Lock the record at the current or specified identity

    DBRLOCK([<xIdentity>]) --> lSuccess

DBRLOCKLIST()          Return an array of the current lock list

   DBRLOCKLIST() --> aRecordLocks

DBRSELECT() :

Return the target workarea number of a relation

DBRSELECT( <nRelation> ) --> nWorkArea

DBRUNLOCK()    

          Release all or specified record locks

    DBRUNLOCK([<xIdentity>]) --> NIL

DBSEEK() : 

Search for a key value

DBSEEK(<expKey>, [<lSoftSeek>]) --> lFound

DBSELECTAR() : 

Change the current workarea

DBSELECTAREA(<nArea> | <cAlias>) --> NIL

DBSETDRIVER() : 

Set the default database driver

DBSETDRIVER([<cDriver>]) --> cCurrentDriver

DBSETFILTER() : 

Set a filter condition

DBSETFILTER(<bCondition>, [<cCondition>]) --> NIL

DBSETINDEX()    

         Empty orders from an order bag into the order list

    DBSETINDEX(<cOrderBagName>) --> NIL

DBSETORDER()

Set the controlling order

    DBSETORDER(<nOrderNum>) --> NIL

DBSETRELAT() :

Relate two workareas

DBSETRELATION( <nArea> | <cAlias>, <bExpr>, [<cExpr>]) --> NIL

DBSKIP() : 

Move relative to the current record

DBSKIP([<nRecords>]) --> NIL

DBSTRUCT() : 

Create an array containing the structure of a database file

DBSTRUCT() --> aStruct

DBUNLOCK()

Release all locks for the current work area

    DBUNLOCK() --> NIL

DBUNLOCKALL()

Release all locks for all work areas

    DBUNLOCKALL() --> NIL

DBUSEAREA() : 

Use a database file in a workarea

DBUSEAREA( [<lNewArea>],
    [<cDriver>],
    <cName>,
    [<xcAlias>],
    [<lShared>],
    [<lReadonly>]) --> NIL

DELETED() : 

Return the deleted status of the current record

DELETED() --> lDeleted

EOF() : 

Determine when end of file is encountered

EOF() --> lBoundary

FCOUNT() : 

Return the number of fields in the current (.dbf) file

FCOUNT() --> nFields

FIELD() : 

Return a field name from the current (.dbf) file

    FIELD/FIELD(<nPosition>) --> cFieldName

FIELDBLOCK() :

Return a set-get code block for a field variable

FIELDBLOCK(<cFieldName>) --> bFieldBlock

FIELDGET() : 

Retrieve the value of a field using the ordinal position of the field in the database structure

FIELDGET(<nField>) --> ValueField

FIELDNAME() : 

Return a field name from the current (.dbf) file

FIELDNAME/FIELD(<nPosition>) --> cFieldName

FIELDPOS() : 

Return the position of a field in a workarea

FIELDPOS(<cFieldName>) --> nFieldPos

FIELDPUT() : 

Set the value of a field variable using the ordinal position of the field in the database structure

FIELDPUT(<nField>, <expAssign>) --> ValueAssigned

FIELDWBLOCK() : 

Return a set-get block for a field in a given workarea

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

FLOCK() : 

Lock an open and shared database file

    FLOCK() –> lSuccess

FOUND() : 

Determine if the previous search operation succeeded

FOUND() --> lSuccess

HEADER() : 

Return the current database file header length

HEADER() --> nBytes

LASTREC() : 

Determine the number of records in the current (.dbf) file

LASTREC() | RECCOUNT()* --> nRecords

LUPDATE() : 

Return the last modification date of a (.dbf) file

LUPDATE() --> dModification

RECCOUNT()* : 

Determine the number of records in the current (.dbf) file

RECCOUNT()* | LASTREC() --> nRecords

RECNO() : 

Return the current record number of a work area

RECNO() --> nRecord

RECSIZE() : 

Determine the record length of a database (.dbf) file

RECSIZE() --> nBytes

RLOCK()

Lock the current record in the active work area

    RLOCK() --> lSuccess

SELECT() : 

Determine the work area number of a specified alias

SELECT([<cAlias>]) --> nWorkArea

USED() : 

Determine if a database file is in USE

USED() --> lDbfOpen