HPlogo Command Interpreter Access and Variables Programmer's Guide: Series HP 3000 Computer Systems > Chapter 3 Setting and Manipulating Variables

Setting User-Defined Variables

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Variables are easily set using the SETVAR command. The command parameters are the variable name and its value. The value can be specified as a single numeric value, a character string, a boolean value, an expression, or the value of another variable. The SHOWVAR command displays the current value of a variable.

In the following example, several variables are set to numeric, string, and boolean values. The SHOWVAR command is used to display the current value of specified variables. Note that wildcard characters, such as the at sign (@), question mark (?), and pound sign (#), can be used to display multiple variables that have similar names.

   :SETVAR CM_PAY_AMT 1000

   :SETVAR CM_FIRST_NAME "CAROL"

   :SETVAR CM_LAST_NAME "SMITH"

   :SETVAR CM_DONE FALSE

   :SHOWVAR CM_PAY_AMT,@NAME

   CM_PAY_AMT = 1000

   CM_FIRST_NAME = CAROL

   CM_LAST_NAME = SMITH

Defining Variable Type

The variable type is defined by your input. Quotation marks specify that the enclosed phrase is a character string. In the previous example, the first and last names are interpreted as string variables. The value 1000, an unquoted numeric string, is interpreted as an integer value. The unquoted word, FALSE, sets the variable to a boolean value. Expressions can also be used to set variable values.

An unquoted string is interpreted as a variable name, not a character string. In such cases, the first variable is loaded with the value of the second variable. The content of the second variable determines the variable type of the new one. In the following example, one new variable CM_NAME is set to the current value of CM_FIRST_NAME, which was set in a previous example.

   :SETVAR CM_NAME CM_FIRST_NAME

   :SHOWVAR CM_NAME

   CM_NAME = CAROL

Displaying User-Defined Variables

As shown in the previous examples, the SHOWVAR command displays the current value of specified user-defined variables. If no parameter information is provided, all user-defined variables for the session are displayed in the order they were created.

   :SHOWVAR

   CM_DONE = FALSE

   CM_FIRST_NAME = CAROL

   CM_LAST_NAME = SMITH

   CM_PAY_AMT = 1000

   CM_NAME = CAROL

Naming Variables

Variables remain set for the duration of the session unless they are deleted or reset to a new value. To avoid collisions with variable names used in command files and UDCs, develop a naming convention that creates unique variable names.

The naming convention used in the preceding examples adds a common prefix to all variables in the command file. In this case, all variables are preceded by CM_. Such a prefix could be the name or abbreviated name of the command file itself. This would provide immediate recognition of the command file that set the variable.

Deleting User-Defined Variables

The DELETEVAR command deletes user-defined variables. It is easier to delete variables in a single maintenance step if each variable name is preceded by a command file identifier. The following example shows how all user-defined variables in the CM command file are deleted by specifying the command file identifier and a wildcard character.

   :DELETEVAR CM_@
Feedback to webmaster