Difference between revisions of "Recital Variables and Constants"

From Recital Documentation Wiki
Jump to: navigation, search
(Assigning a Value to a Variable)
(Assigning a Value to a Variable)
Line 31: Line 31:
 
====Assigning a Value to a Variable====
 
====Assigning a Value to a Variable====
  
Values are assigned to memory variables using the [[STORE]] command or the equals [[=]] operator.
+
Values are assigned to memory variables using the [[STORE]] command, the equals operator or the inline assignment [[Inline Assignment|:=]] operator.
  
  
 
<code lang="recital">
 
<code lang="recital">
 
store 'new value' to cVAR1
 
store 'new value' to cVAR1
cVAR1 = 'new value'
+
cVAR1 = 'newer value'
 +
cVAR1 := 'newest value'
 
</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]] command can assign a value to more than one memory variable in a single command.
  
  

Revision as of 13:26, 21 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 ten 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 or LOCAL and will be initialized as a logical false (.F.).


public cVar1
private cVar2
local cVar3


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.

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

Checking Whether a Variable Exists

Variable Scope

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

Numeric Constants

Date Constants

Logical Constants

Datetime Constants

Currency Constants

Summary