Skip to content
Property Value
Hex Value $BB54
Categories
Localizations
  • FR: EffVar

DelVar

Overview

Deletes from memory the contents of variable.

Availability: Token only available from within the Basic editor.

Syntax

DelVar variable

Arguments

NameTypeOptional
variable

Location

prgm, CTL, G:DelVar


Description

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:

DelVar also does not count as a line with respect to IS>(, DS<(, and single-line If statements.

:If B
:Then
:DelVar A
:Disp "Hello
:End
can be
:If B
:DelVar ADisp "Hello

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 deallocate the variable from the RAM. DelVar is also significantly slower for zeroing real variables when compared to using to set the variable to 0. The speed difference becomes apparent when the value is reset many times but is not a major factor if only used sparingly.

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.

See Also


Source: parts of this page were written by the following TI|BD contributors: AntKou, basickevin, burr, DarkerLine, GoVegan, jonbush, kg583, Myles_Zadok.

History

Calculator OS Version Description
TI-83 1.010 Renamed DelVar to DelVar

Last update: July 29, 2024 19:47:40
Created: February 23, 2023 23:15:01
Authors: Adrien Bertrand