Difference between revisions of "Recital Variables and Constants"

From Recital Documentation Wiki
Jump to: navigation, search
(Currency Constants)
(Recital Variables and Constants)
Line 20: Line 20:
 
</code>
 
</code>
  
[[PUBLIC]] variables are globally visible, they are accessible and can be changed from any part of an application.  If the application is run from the Interactive Prompt, then any public variables can still be accessed even after the application ends.  Any variables created at the Interactive Prompt are automatically created as public variables.
+
[[PUBLIC|Public]] variables are globally visible, they are accessible and can be changed from any part of an application.  If the application is run from the Interactive Prompt, then any public variables can still be accessed even after the application ends.  Any variables created at the Interactive Prompt are automatically created as public variables.
  
[[PRIVATE]] variables are only visible within the declaring module (program, procedure, User Defined Function) and any modules called by that declaring module.  Any variables accessed within a module that are not pre-declared are automatically created as private variables.  When the module returns, then all of the memory variables and arrays that were declared by the PRIVATE command are released.
+
[[PRIVATE|Private]] variables are only visible within the declaring module (program, procedure, User Defined Function) and any modules called by that declaring module.  Any variables accessed within a module that are not pre-declared are automatically created as private variables.  When the module returns, then all of the memory variables and arrays that were declared by the PRIVATE command are released.
  
[[LOCAL]] variables are only visible within the declaring module and are released when the module returns. LOCAL variables differ from PRIVATE variables in that a LOCAL variable is not visible to lower level procedures or functions.
+
[[LOCAL|Local]] variables are only visible within the declaring module and are released when the module returns. LOCAL variables differ from PRIVATE variables in that a LOCAL variable is not visible to lower level procedures or functions.
  
[[STATIC]] variables
+
[[STATIC|Static]] variables
 
{{YLM todo}}
 
{{YLM todo}}
  
 
====Assigning a Value to a Variable====
 
====Assigning a Value to a Variable====
  
Values are assigned to memory variables using the [[STORE]] command, the equals = operator or the inline assignment [[Inline Assignment|:=]] operator.
+
Values are assigned to memory variables using the [[STORE|store]] command, the equals = operator or the inline assignment [[Inline Assignment|:=]] operator.
  
 
<code lang="recital">
 
<code lang="recital">
Line 39: Line 39:
 
</code>
 
</code>
  
Note that the [[STORE]] command can assign a value to more than one memory variable in a single command.
+
Note that the [[STORE|store]] command can assign a value to more than one memory variable in a single command.
  
 
<code lang="recital">
 
<code lang="recital">
Line 48: Line 48:
 
====Changing the Type of a Variable====
 
====Changing the Type of a Variable====
  
The [[TYPE()]] or [[VARTYPE()]] functions can be used to determine the data type of any variable.
+
The [[TYPE()|type()]] or [[VARTYPE()|vartype()]] functions can be used to determine the data type of any variable.
  
 
* All Variables
 
* All Variables
** [[CAST()]] - perform data type conversion
+
** [[CAST()|cast()]] - perform data type conversion
** [[ETOS()]] - perform data type to string conversion  
+
** [[ETOS()|etos()]] - perform data type to string conversion  
 
* Character Variables:
 
* Character Variables:
 
** [[Working With String Data in Recital#String Conversion Functions|String Conversion Functions]]
 
** [[Working With String Data in Recital#String Conversion Functions|String Conversion Functions]]
Line 60: Line 60:
 
** [[Working With Numeric Data in Recital#Numeric Conversion Functions|Numeric Conversion Functions]]
 
** [[Working With Numeric Data in Recital#Numeric Conversion Functions|Numeric Conversion Functions]]
 
* Logical Variables
 
* Logical Variables
** [[LTOS()]] - perform logical to string conversion
+
** [[LTOS()|ltos()]] - perform logical to string conversion
  
 
====Checking Whether a Variable Exists====
 
====Checking Whether a Variable Exists====
  
The [[ISSET()]] function can be used to check whether a variable exists.
+
The [[ISSET()|isset()]] function can be used to check whether a variable exists.
  
 
<code lang="recital">
 
<code lang="recital">
Line 76: Line 76:
 
...
 
...
  
To manually release a memory variable, use the [[UNSET()]] function:
+
To manually release a memory variable, use the [[UNSET()|unset()]] function:
  
 
<code lang="recital">
 
<code lang="recital">
Line 106: Line 106:
 
</code>
 
</code>
  
The [[TYPE()]] function returns 'C' for character strings.
+
The [[TYPE()|type()]] function returns 'C' for character strings.
  
 
====Numeric Constants====
 
====Numeric Constants====
Line 116: Line 116:
 
</code>
 
</code>
  
The [[TYPE()]] function returns 'N' for numerics.
+
The [[TYPE()|type()]] function returns 'N' for numerics.
  
 
====Date Constants====
 
====Date Constants====
A combination of digits and separators delimited by curly braces {}. The format is determined by the [[SET DATE]] and [[SET CENTURY]] commands.
+
A combination of digits and separators delimited by curly braces {}. The format is determined by the [[SET DATE|set date]] and [[SET CENTURY|set century]] commands.
  
 
<code lang="recital">
 
<code lang="recital">
// SET DATE is BRITISH, SET CENTURY is OFF
+
// set date is BRITISH, set century is OFF
 
{21/01/09}
 
{21/01/09}
// SET DATE is AMERICAN, SET CENTURY is ON
+
// set date is AMERICAN, set century is ON
 
{01/21/2009}
 
{01/21/2009}
// SET DATE is GERMAN, SET CENTURY is ON
+
// set date is GERMAN, set century is ON
 
{21/01/2009}
 
{21/01/2009}
// SET DATE is JAPAN, SET CENTURY is ON
+
// set date is JAPAN, set century is ON
 
{2009/21/01}
 
{2009/21/01}
 
</code>
 
</code>
  
The [[TYPE()]] function returns 'D' for dates.
+
The [[TYPE()|type()]] function returns 'D' for dates.
  
 
====Logical Constants====
 
====Logical Constants====
 
A choice of two values, .T. for true, .F. for false
 
A choice of two values, .T. for true, .F. for false
  
The [[TYPE()]] function returns 'L' for logicals.
+
The [[TYPE()|type()]] function returns 'L' for logicals.
  
 
====Datetime Constants====
 
====Datetime Constants====
A combination of digits and separators delimited by curly braces {}. The format is determined by the [[SET DATE]] and [[SET CENTURY]] commands.
+
A combination of digits and separators delimited by curly braces {}. The format is determined by the [[SET DATE|set date]] and [[SET CENTURY|set century]] commands.
  
 
<code lang="recital">
 
<code lang="recital">
// SET DATE is BRITISH, SET CENTURY is OFF
+
// set date is BRITISH, set century is OFF
 
{21/01/09 02:11:12 PM}
 
{21/01/09 02:11:12 PM}
// SET DATE is AMERICAN, SET CENTURY is ON
+
// set date is AMERICAN, set century is ON
 
{01/21/2009 05:09:09 AM}
 
{01/21/2009 05:09:09 AM}
// SET DATE is GERMAN, SET CENTURY is ON
+
// set date is GERMAN, set century is ON
 
{21/01/2009 11:30:00 PM}
 
{21/01/2009 11:30:00 PM}
// SET DATE is JAPAN, SET CENTURY is ON
+
// set date is JAPAN, set century is ON
 
{2009/21/01 12:10:10 AM}
 
{2009/21/01 12:10:10 AM}
 
</code>
 
</code>
  
The [[TYPE()]] function returns 'T' for datetimes.
+
The [[TYPE()|type()]] function returns 'T' for datetimes.
  
 
====Currency Constants====
 
====Currency Constants====
Line 163: Line 163:
 
</code>
 
</code>
  
The [[TYPE()]] function returns 'Y' for currency values.
+
The [[TYPE()|type()]] function returns 'Y' for currency values.
  
 
====Summary====
 
====Summary====

Revision as of 11:06, 23 October 2009

Recital Variables and Constants

An Introduction to Recital Variables

Naming and Creating a Variable

Memory variable names must begin with a letter (A-Z, a-z) or an underscore (-), followed by any combination of letters, digits or underscores. The variable name can be of any length, but only the first 32 characters are significant, so these must be unique. Recital ignores the case of letters, so m_var, M_VAR, and m_VaR would all be treated as the same memory variable name. The name given to a memory variable has no bearing on the type of data that is, or can be, stored in it. In fact, the type of data stored in a particular variable can be changed at any time, although this needs to be carefully controlled so that inappropriate operations are not attempted. e.g.

m_var = 1234
m_var = 'a character value'
? m_var + 100

Values can be assigned to memory variables without those memory variables having been pre-declared, but it is generally accepted that the pre-declaration of memory variables is good programming practice. Variables can be declared as PUBLIC, PRIVATE, LOCAL or STATIC and will be initialized as a logical false (.F.).

public cVar1
private cVar2
local cVar3
static cVar4

Public variables are globally visible, they are accessible and can be changed from any part of an application. If the application is run from the Interactive Prompt, then any public variables can still be accessed even after the application ends. Any variables created at the Interactive Prompt are automatically created as public variables.

Private variables are only visible within the declaring module (program, procedure, User Defined Function) and any modules called by that declaring module. Any variables accessed within a module that are not pre-declared are automatically created as private variables. When the module returns, then all of the memory variables and arrays that were declared by the PRIVATE command are released.

Local variables are only visible within the declaring module and are released when the module returns. LOCAL variables differ from PRIVATE variables in that a LOCAL variable is not visible to lower level procedures or functions.

Static variables Template:YLM todo

Assigning a Value to a Variable

Values are assigned to memory variables using the store command, the equals = operator or the inline assignment := operator.

store 'new value' to cVAR1
cVAR1 = 'newer value'
cVAR1 := 'newest value'

Note that the store command can assign a value to more than one memory variable in a single command.

store 'new value' to cVAR1, cVAR2

Accessing a Variable

Changing the Type of a Variable

The type() or vartype() functions can be used to determine the data type of any variable.

Checking Whether a Variable Exists

The isset() function can be used to check whether a variable exists.

if isset(m_var)
  // m_var exists
endif

Variable Scope

...

To manually release a memory variable, use the unset() function:

if isset(m_var)
  unset(m_var)
endif

Understanding Recital Variable Types

Recital Character Variables

Recital Numeric Variables

Recital Date Variables

Recital Logical Variables

Recital Datetime Variables

Recital Currency Variables

Recital Constants

Character Constants

A string of ASCII characters up to 65535 characters in length.

Delimited by double quotes "", single quotes ‘’ or square brackets [].

[hello]
'goodbye'
"RECITAL"
"1234.56"
"12/12/2009"

The type() function returns 'C' for character strings.

Numeric Constants

An integer number of up to 16 digits (0-9) or a floating point number of up to 25 digits (9 are reserved for decimal places) and one decimal point.

1234
1234.56

The type() function returns 'N' for numerics.

Date Constants

A combination of digits and separators delimited by curly braces {}. The format is determined by the set date and set century commands.

// set date is BRITISH, set century is OFF
{21/01/09}
// set date is AMERICAN, set century is ON
{01/21/2009}
// set date is GERMAN, set century is ON
{21/01/2009}
// set date is JAPAN, set century is ON
{2009/21/01}

The type() function returns 'D' for dates.

Logical Constants

A choice of two values, .T. for true, .F. for false

The type() function returns 'L' for logicals.

Datetime Constants

A combination of digits and separators delimited by curly braces {}. The format is determined by the set date and set century commands.

// set date is BRITISH, set century is OFF
{21/01/09 02:11:12 PM}
// set date is AMERICAN, set century is ON
{01/21/2009 05:09:09 AM}
// set date is GERMAN, set century is ON
{21/01/2009 11:30:00 PM}
// set date is JAPAN, set century is ON
{2009/21/01 12:10:10 AM}

The type() function returns 'T' for datetimes.

Currency Constants

A monetary value prefixed with a dollar sign, '$', and consisting of up to 9 digits and 4 decimal places.

$123456789.1234
$99

The type() function returns 'Y' for currency values.

Summary