What are basic data types ?

Types of FIELD variables are defined in STRUCTURE of tables (.dbf files).

For other type (memory) variables, Clipper isn’t a “strong typing” language. Programmers not obliged to define variables with type before referenced (used); variables are typed “on the fly” that is by assigning value.

Notes :

  • “M” (memo) type is usable only in .dbf files, there isn’t “M” type variable. In terms of operation, “M” data is similar  to character type.
  • Harbour has 6 scalar types : Nil, String, Date, Logical, Number, Pointer, and 4 complex types: Array, Object, CodeBlock, and Hash. Types cited here are BASIC type: String, Number, Logical and Date.
  • For more info about data types please refer here.
  • Harbour supports also “extended” field types; see here.
  • There is also NIL type that has only one allowable value: NIL. NIL is not “undefined”, simply “nothing”.
  • This program also use “ALTERNATE” writing feature for display program output. This is handy for especially debugging and logging purposes.

/*

A little test program to explore basic data types in Clipper.

*/   

#include <hmg.ch>

PROC MAIN

   * Some global settings
   SET( _SET_EOF, .F. )                // Don't put EOF marker to end of files built
   SET CENTURY ON                      // Display Century portion of dates type data
   
   * Set test file name
   cTestFNam := "DataTypes.txt"        // Name of test file
   
   * Set and open alternate file
   SET ALTERNATE TO (cTestFNam)        // Redirect screen (console) output 
                                       // (results of ? commands) to that file  
   SET ALTERNATE ON                    // Open alternate writing  
   
   * Assign values to variables
   cCharVar := "This is a character data"   // Assign astring value to this variable 
   nNumrVar := 123.456                // Assign this numeric value to this variable 
   lLogiVar := .T.                    // Assign this logical value to this variable    
   dDateVar := DATE()                 // Assign this date type value (date of day) 
                                      // to this variable  
   
   * Write variable names and value
   ? "cCharVar :", TYPE( "cCharVar" ), cCharVar
   ? "nNumrVar :", TYPE( "nNumrVar" ), nNumrVar
   ? "lLogiVar :", TYPE( "lLogiVar" ), lLogiVar
   ? "dDateVar :", TYPE( "dDateVar" ), dDateVar
   
   * Close alternate writing and file
   SET ALTE OFF                             // Close alternate writing 
   SET ALTE TO                              // Close alternate file 
   
   * Run Notepad of Windows and send to it my test file
   EXECUTE FILE "NOTEPAD.EXE" PARAMETERS cTestFNam 

RETU
   
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

One response to “What are basic data types ?

  1. Pingback: What is / What Are … | Viva Clipper !

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.