<< Click to Display Table of Contents >> Navigation: 1. Starting Guides > 1. Starting Guide |
Starting Guide
Using Variables
Update: Due to the new SAV.Save and SAV.Restore Command the use of §§XXX-Variables (Script-local Variables) is not more recommended.
Just use the normal $$XXX (Global Variables) and make them "local" using the SAV.-and SAV.Restore Command.
Variables are like containers that hold important information in a program or script. They help us keep track of different kinds of data, such as numbers or words. Just imagine having different boxes to store different things.
Variables are good because they allow us to:
1. Remember things: We can give a name to a variable, like "myNumber," and put a number inside it. Then we can use that number later in our program whenever we need it.
2. Change things: We can update the value inside a variable. For example, if we have a variable called "score" and we win a game, we can increase the score by adding more points to it.
3. Solve problems: Variables help us solve puzzles or perform calculations. We can use them to add numbers together, find the average of a group of numbers, or even create stories with different characters and their actions.
4. Make things easier to understand: By giving variables meaningful names, we can make our code easier to read and understand. Instead of using numbers directly in our program, we can use variable names like "numberOfApples" or "playerName" to make it clear what the values represent.
5. Play and be creative: Variables allow us to be creative and make our programs more interactive. We can create games where the player's score changes, or stories where the characters' names can be different each time we play.
In simple words, variables help us remember, change, and solve problems with different kinds of information in our programs. They make programming more fun and allow us to create amazing things with our imagination.
Intention
In the SPR (Smart Package Robot Script), variables are symbols that store numerical, text, or string data. They are used in scripts to store and manipulate information. In the SPR, variables are identified by their names, which always start with two dollar signs ($$). Here are some examples of valid variable names in the SPR:
$$A00
$$HAL
Please do NOT use Variables like:
$$000 (3*Numeric) as these may have another usage and reference the Execution Stack.
These names can be chosen freely by the script writer, as long as they start with two dollar signs.
Variables allow scripts to be more dynamic and flexible, as they can hold different values at different points in the script. By using variables, you can store and retrieve data, perform calculations, and make your scripts more powerful and adaptable to different situations.
Variables are Symbols which contain numerical, text or string-data. When used in a script, the variable name is replaced with the variable content.
With the SPR, any Variable starts with two $$ Signs. The following are valid names for variables.
$$AAA
$$FRA
You can even use Special-Characters and the Variable-Name will still be valid, like:
$$--- or $$###
Yet, we do not recommend this, unless for special Purposes.
Variables are Case-Sensitive!
Therefore this is not going to work:
VAR.$$FRA=10
MBX.$$fra
END.
This is going to work:
VAR.$$FRA=10
MBX.$$FRA
END.
Try the example below.
VAR.$$FIL=C:\MyDir\Mydir2
MBX.The dir was:$crlf$ $$FIL
ENR.
' You can take that further ...
VAR.$$TXT=Hallo world
VAR.$$TXA=$$TXT!
MBX.$$TXA
ENR.
When working with variables in the SPR, it is important to note that:
1. Variables do not need to be explicitly declared, and memory allocation is handled automatically.
2. Variables can be defined, changed and cleared at runtime.
3. Variables can only be accessed at runtime, the preprocessor does not have access to the variable's content.
4. Each variable has an internal variable type, which can be determined and manipulated with specific commands.
The SPR's handling of variables allows for a flexible and efficient programming experience, while also providing the necessary tools to work with variable types and memory allocation.
Important!
How do you get the §-Character on non-german Keyboards?
Press "ctrl-B".
The SPRE-Editor will give you the § character when you press left "Ctrl" and "B" on your keyboard.
Pressing "ctrl-H" will give you the | (Pipe) Character.
Here are some of the different Methods to assign values to variables.
• The : - Definiton-Command
• VAR. - Variable Set Value/Clear
• VBA. - Variable Binary Append