# Thread: Are local variables "saved in memory"...

1. ## Are local variables "saved in memory"...

or do they become null or 0 value at end of program
will OD retain a value after the m2% is read and cycle start is pressed
so I can continue to use the calculated value of OD in different equations
for example if in a program I have an equation
...
IF [V28 EQ 0] N10
OD=DFIX[V28/3.1416]+V29+V30
V2=OD
V28=0 V29=0 V30=0
GOTO N20
N10
V2=PD-.2
V3=OD
N20
...
or will I need to add a bunch of conditions before the m2, or learn more about scheduling or... who knows but it will be fun trying.
CHEERS!

2. You seem to be using a combination of "User Variables" (V#'s) and "Local Variables" (PD,OD etc )

User variables ( V#= in lathes, VC#= in mills ) are stored to a designated area, switch the m/c OFF and ON, they are still there. You can also look at the actual value at any time
but
Local Variables are stored in ROM, now turn the m/c OFF and ON, and they're gone

Try putting them into User Variables, you can step thru a program, and double check your calcs to those recorded

Code:
```
...
IF [V28 EQ 0] N10
V1=DFIX[V28/3.1416]+V29+V30
V2=OD
V28=0 V29=0 V30=0
GOTO N20
N10
V2= [V4 -0.2]
V3=V1
N20
...```

3. The problem I am having is I use 29 of my 32 available common variables and some of those have more than 1 function, the other 3 are used to output calculated equation values so we can double check ourself before cycling. Im plum outta common variables, and I want to avoid online program editing.
The input I have been getting in this forum has been really helpful I have the actual g-code seperated from most of my local variables, and now we are building the local variable library, and most of the common variables get defined by the information in the local variable program along with at least 3 specific common variables. A lil crazy but I just got caught up in User Task

Thanks S'more
CHEERS!

4. You could use local variables and just set them at the beginning of your program. You will have up to 128 of them available plus the 32 common variables. If you need more, reset them to new values part way through the program if need be.

Will that work for you?

Best regards,

5. Here is a little good news bad news scenario.. I have now learned how to store values from the program into tool data values via VTOFx/z and VNSRx/z
now the bad news is I have learned this neat little trick since I am using that space now to store part values. This scares me a little... okay alot
I fear one day in the future some poor soul will swap a tool station and cause some havoc.
Our problem is when we reset the program in order to restart(usually for a taper correction) local variables seem to lose their value. I do hope to find another place to store these "local values" than in tool data , but since I am using tools 13-32 as local variables I think its unlikely someone that doesn't understand the prog/mach a little will define these offsets...being only a 12 tool turret.
fun fun fun
CHEERS!

6. "Local" variables live and die within the currently running program only.
As soon as the program ends, so do the "local" variables.
Storing "variable" information within tool offsets in my mind will only lead to many problems.
When you say you only have 12 tools in the turret and you will not be using the other offsets, what about grooving tools? I have always used two sets of offsets to define each grooving tool. One set per side of the tool.
At least you are aware that this could lead to disaster...