Next: 13.2 Units of Variables Up: 13. Programming With Variables Previous: 13. Programming With Variables Contents Index

# 13.1 Types of Variables

There are two ways to define variables for use in part programs. The most obvious is an explicit reference to the variable in the currently used variable file. Each time the EMC starts up it loads a variable file. The default variable file is emc.var but this can be changed in the .ini file. For convenience, this paper uses emc.var as if it were the currently loaded file.

When the following line is placed in emc.var, it explicitly defines a variable.

1000 55

The number 1000 is the name of the variable, and once you have defined it and read it into the interpreter, you can use that name in your g-code program if you place a hash sign in front of it. With the line above, we also assigned variable #1000 the value of 55 by placing that number on the same line after the variable name. Any time that you name a variable and assign a value to it in emc.var you have explicitely defined that variable.

Implicit reference to a variable is done when a name is used within a program but no reference is made to that variable in the variable file. The following line of code in a part program will initialize a variable named 1000 and assign it a value of 55.

#1000 = 55

Implicit variables initialize to zero value if no assignment is made before a variable is first used. Implicit variables disappear when the EMC interpreter is shut down but will hold a current value as long as the EMC is running.

Explicit variables act just like implicit variables while the EMC is running but reloading the variable file will reset explicit variables to the value that they are assigned in the variable file. When EMC is shut down normally, the current values of all explicit variables are written into emc.var. Since explicit variables can change value from one run of EMC to the next, they may not contain the values that you expect when you restart your machine.

The EMC doesn't care very much what we name variables or what we use them for. For explicitly defined variables, the EMC cares only that they are two numbers in a row on a line by themselves in the emc.var file. For implicitly defined variables, the EMC cares not a whit. The only complaints that you might get from the EMC is if a reference to a variable makes a reference to an unknown word, or is out of range for a distance, or concerns tool compensation. While you are writing or using variables you will want to refer to and probably stay away from those variables listed in emc.ini that are used to set up the coordinate systems.

Next: 13.2 Units of Variables Up: 13. Programming With Variables Previous: 13. Programming With Variables Contents Index