Variable: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(edit)
(edit)
Line 5: Line 5:
The whole process that you have just done with your mental memory is a simile of what a computer can do with two variables. The same process can be expressed in BR with the following instruction set:  
The whole process that you have just done with your mental memory is a simile of what a computer can do with two variables. The same process can be expressed in BR with the following instruction set:  


00010 let a = 5
00010 let a = 5
 
00020 let b = 2
00020 let b = 2
00030 let a = a + 1
 
00040 let result = a - b
00030 let a = a + 1
 
00040 let result = a - b


There are two categories of '''variables''' in [[Business Rules!]].
There are two categories of '''variables''' in [[Business Rules!]].

Revision as of 13:16, 5 January 2012

A variable is a way of referring to a memory location used in a computer program.

Let us think that I ask you to retain the number 5 in your mental memory, and then I ask you to memorize also the number 2 at the same time. You have just stored two different values in your memory. Now, if I ask you to add 1 to the first number I said, you should be retaining the numbers 6 (that is 5+1) and 2 in your memory. Values that we could now for example subtract and obtain 4 as result.

The whole process that you have just done with your mental memory is a simile of what a computer can do with two variables. The same process can be expressed in BR with the following instruction set:

00010 let a = 5
00020 let b = 2
00030 let a = a + 1
00040 let result = a - b

There are two categories of variables in Business Rules!.

  1. Numeric
  2. String

Additionally either of these types of variables may be contained in arrays.

Naming Requirements

Variable Naming Requirements apply to both String and Numeric variables.

  • May contain any letter, number or underscore.
  • Must begin with a letter or an underscore.
  • May not contain dashes, spaces or any characters other than letters and underscores. In other words, characters such as - , ; : * ! @ # $ % ^ & ( ) + and many others are not allowed in a variable name.
  • May not exceed 30 characters.
  • May not start with "fn" as that prefix is reserved for User Defined Functions.
  • BR variable names are case-insensitive, so myVariable$ and Myvariable$ will refer to the exact same variable.
  • String variable names must end with a $.


Case Insensitivity

Dimensioning Variables

Variable Scope

Initialization of Variables

Numeric

Numeric variables are one of two variable types available in BR.

Example

00010 let a = 10
00020 let b = a + 1
00030 let c = 2 * b

To learn more about the use of numeric variables, refer to the Numeric operators section


String

<1-30 alphanumeric characters and underscores, the first of which must be a letter (but not FN) which ends in a $. They also cannot be reserved words>

A string or string variable is a variable which may contain any type of characters. Strings are one of the two types of variables available in BR, the other is numeric. Strings may be formed into arrays of strings.

  • All normal Variable Naming Requirements apply
  • Variable name must end with $ (the $ does not count against the 30 character variable name limitation)
  • Default Dim Length of 18 characters

Below is an example of the use of a string in a short program:

00010 let myString$ = "BR kicks butt"
00020 print myString$

To learn more about the use of string variables, refer to the String Operations section.