The DelVar Command

DELVAR.GIF

Command Summary

Deletes a variable from memory.

Command Syntax

DelVar variable

Menu Location

While editing a program, press:

  1. PRGM to enter the PRGM menu
  2. ALPHA TAN to choose DelVar, or use arrows

Calculator Compatibility

TI-83/84/+/SE

Token Size

2 bytes

The DelVar command deletes the contents of a variable (and thus the variable itself) from memory. You can use the DelVar command with any variable: reals, lists, matrices, strings, pictures, etc. However, you cannot use DelVar on specific elements of a matrix or string; it will actually throw a ERR:SYNTAX error. (It also does not work on programs, unfortunately.)

If the DelVar command is used with a real variable, the variable is not only deleted from memory but automatically set to zero the next time it is used. This is equivalent to using store (→) to manually set the variable yourself. Because the DelVar command is two bytes instead of one, there is no size difference between the two.

:0→A
same as
:DelVar A

While there is no size difference between the two, DelVar does have some problems that go along with using it. If used in a For loop to delete the counter variable or used to delete the variable and/or value in the IS>( or DS<( commands before using them, it will cause an ERR:UNDEFINED error.

This is a result of the way that the interpreter in TI-Basic is designed, so there is nothing you can do about it. You just need to be cognizant of it when using DelVar in a For loop or together with IS>( or DS<(.

Advanced Uses

When you are done using variables, you should delete them at the end of the program with the DelVar command to cleanup. Each variable takes up a set amount of space (for example, a real variable is 15 bytes), and the more variables you can delete the more free memory is available. Free memory helps your programs run faster and allows you to pack more things on your calculator.

Because the DelVar command doesn't update the Ans variable, you can use DelVar and the current value in Ans will still be preserved for later use.

Optimizations

The DelVar command does not need a line break or colon (which indicates a new line of code) following the variable name. This allows you to make chains of variables (organized in whatever order you want), and it saves a byte for each line break or colon removed.

:DelVar A
:DelVar B
can be
:DelVar ADelVar B

Besides making chains of variables, the DelVar command also allows you to take the command from the next line and put it immediately after the DelVar command.

:DelVar A
:Disp "Hello
can be
:DelVar ADisp "Hello

There are, however, two cases in which the following statement will be ignored, so you should add a newline:

  • The End from an If statement.
  • A Lbl command.

Command Timings

The speed of the DelVar command depends on the circumstance where it is used. When the variable already exists, DelVar is slower because it has to perform garbage collection. When the variable does not exist, however, its speed is greatly increased because it does not have to do anything to setup the variable.

Error Conditions

  • ERR:SYNTAX is thrown when trying to delete a system variable (e.g. DelVar Xmin) or a program, even though this is syntactically correct.
  • ERR:UNDEFINED is thrown if you delete the loop variable while inside the loop, or delete the variable used in IS>( or DS<(.
  • ERR:ARCHIVED is thrown if you use DelVar on an archived variable.

Related Commands

See Also

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License