HPlogo Using HP 3000 MPE/iX:\Advanced Skills Tutorial: HP 3000 MPE/iX Computer Systems > Chapter 8 Solutions

Solutions to Module 6: Variables and Expressions

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Glossary

 » Index

Check Your Answers

  Is Your Answer ... ? If Not, Start With
1.

VAR_1

VARIABLE_1

Lesson 1
2.

HPPROMPT or HPPATH

Lesson 1
3. FALSE Lesson 1
4. TRUE Lesson 1
5.

SHOWVAR VARIABLE1 or

ECHO !VARIABLE1

Lesson 1
6.

ECHO HELLO ___ WELCOME TO THE ...

- OR -

SETVAR A "HELLO __ WELCOME TO THE ..."

SHOWVAR Aor ECHO !A

Lesson 2
7.

INPUT USERNAME;PROMPT="What is your name?"

ECHO HELLO !USERNAME __ WELCOME TO THE ...

Lesson 2
8. You must explicitly dereference the value of VAR_A by using the statements in b and c. Lesson 2
9.
  1. CFA: It prints: *** HELLO JULIO FROM SPAIN *** and quits.

    CFB: It prints: *** HELLO JULIO FROM SPAIN *** and reprompts.

  2. CFA: It prints *** SORRY, NO MESSAGE *** and quits.

    CFB: It prints *** SORRY, NO MESSAGE *** and quits.

  3. CFA: It prints: *** HELLO GINA FROM ITALY *** and quits. It never gives you a chance to enter the //.

    CFB: It prints: HELLO GINA FROM ITALY *** and quits after you enter //.

Lesson 2

Lesson 1 Understanding Variables

Q 6-1

The following are acceptable names for variables:

 Variable Name
b. CIERROR
c. FRED_FLINTSTONE
d. HPINPRI
f. _JAMES_BOND

Q 6-2

According to the values assigned them (by the user or the system), the variables listed below are of the specified type:

 VariableType
HPJOBLIMIT(number of jobs allowed to run):integer
HPJOBCOUNT(number of jobs currently running):integer
RESPONSE(user response - either Y or N):string
FILE NAME(user-supplied file name):string

Q 6-3

Hint: HELP VARIABLESReturn. According to the Help facility, each of the following variables are defined.

Hint: SHOWVAR variablenameReturn

Their current values depend on your system:

VariableCurrent ValueDefinition
HPJOBLIMIT7Current job limit.
HPSESLIMIT60Current session limit.
HPPROMPT:The initial system prompt.
HPPATHHPGROUP,PUB,PUB.SYSCurrent search path
HPVERSIONX.11.50Current version of operating system.
HPUSERUSER1User name.
HPSESCOUNTvaries with the systemCurrent number of sessions.

Q 6-4

To list all the system-defined and user-defined variables, enter this command:

SHOWVAR @

Q 6-5

The system-defined variables in the STATS command file are the following:

   HPJOBLIMIT

   HPJOBCOUNT
Q 6-6

No, neither variable is user-modifiable.

Q 6-7

In the LF command file, the three user-defined variables are:

   RESPONSE

   FILE NAME

   OPTION

Exercise 6-1: Variables

  1. To define a variable called MYPROMPT and assign it the value currently stored in HPPROMPT, enter the following:

    SETVAR MYPROMPT HPPROMPT

  2. To display the value of MYPROMPT, enter the following:

    SHOWVAR MYPROMPT

  3. To delete MYPROMPT and verify that it is gone, enter the following:

       DELETEVAR MYPROMPT
    
       SHOWVAR MYPROMPT
    

    MYPROMPT is a user-defined variable.

    HPPROMPT is a system-defined variable.

    You cannot delete system-defined variables.

********* End of Exercise 6-1 **********

Lesson 2 Using Variables and Expressions

Q 6-8

The method of dereferencing used in the two ECHO statements of the STATS command file is explicit dereferencing (exclamation points are used).

Q 6-9

To give the three user-defined variables, USER, GROUP, and ACCT, the same values as those currently stored in the system-defined variables, HPUSER,HPGROUP, and HPACCT, you would do the following:

   SETVAR USER, HPUSER

   SETVAR GROUP, HPGROUP

   SETVAR ACCT, HPACCT
Q 6-10

According to the IF-THEN statement in the STATS file, the following messages are displayed in each of the following situations:

  1. The current number of jobs is 10 and the job limit is 12.

       ***APPROACHING JOB LIMIT ---
    
       STREAM JOB LATER
    
    
    
    
    
  2. The current number of jobs is 5 and the job limit is 10.

       ***NUMBER OF JOBS IS STILL REASONABLE ---
    
       STREAM JOB NOW
    
    
    
    
    

Exercise 6-2: IF-THEN-ELSE Statement

1.

Your IF-THEN-ELSE statement should look like this:

   IF HPSESCOUNT >= (HPSESLIMIT*3)/4 THEN

      SHOWVAR HPSESCOUNT

      SHOWVAR HPSESLIMIT

      ECHO ***TOO MANY PEOPLE ON SYSTEM --- LOG OFF NOW***

   ELSE

      SHOWVAR HPSESCOUNT

      SHOWVAR HPSESLIMIT

      ECHO *** CURRENT SESSION LIMIT NOT EXCEEDED ***

   ENDIF

****************** End of Exercise 6-2 *************

Q 6-11

As long as you respond with anything other than //, you will be prompted continually for file names.

Q 6-12

To terminate being prompted for any more file names, you must respond with //.

Exercise 6-3: WHILE Loop

  1. Your CF command file should look like this:

       INPUT RESPONSE;PROMPT="Do you want to change the prompt? (Y or N): "
    
          IF RESPONSE = 'Y' THEN
    
             SETVAR MYRESP 'N'
    
             WHILE MYRESP = 'N' DO
    
                 INPUT HPPROMPT;PROMPT="Enter your new prompt (10 char. max): "
    
                 ECHO !HPPROMPT
    
                 INPUT MYRESP;PROMPT="Is this prompt OK? (Y or N): "
    
             ENDWHILE
    
          ELSE
    
             ECHO Current prompt remains in effect !HPPROMPT
    
       DELETEVAR RESPONSE,MYRESP
    
  2. When you enter your final prompt, this prompt should be displayed:

    USERx:

  3. Use this command to change HPPROMPT to the initial system prompt:

       SETVAR HPPROMPT,":"
    

************ End of Exercise 6-3 ************

Feedback to webmaster