[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP BASIC for OpenVMS
Reference Manual


Previous Contents Index


MOVE

The MOVE statement transfers data between a record buffer and a list of variables.

Format



Syntax Rules

  • Chnl-exp is a numeric expression that specifies a channel number associated with a file. It must be immediately preceded by a number sign (#).
  • Move-item specifies the variable or array to which or from which data is to be moved.
  • Parentheses indicate the number of dimensions in a numeric array. The number of dimensions is equal to the number of commas plus 1. Empty parentheses indicate a one-dimensional array, one comma indicates a two-dimensional array, and so on.
  • Str-var and str-array specify a fixed length string variable or array. Parentheses indicate the number of dimensions in a string array. The number of dimensions is equal to the number of commas plus 1. You can specify the number of bytes to be reserved for the variable or array elements with the =int-exp clause. The default string length for a MOVE FROM statement is 16. For a MOVE TO statement, the default is the string's length.
  • The FILL, FILL%, and FILL$ keywords allow you to transfer fill items of a specific data type. Table 3-1 shows FILL item formats, representations, and storage requirements.
    • If you specify a data type before the FILL keyword, the fill is of that data type. If you do not specify a data type, the fill is of the default data type. Data-type can be any HP BASIC data type keyword or a data type defined by a RECORD statement. Data type keywords, size, range, and precision are listed in Table 1-2.
    • FILL items following a data type other than STRING cannot end with a dollar sign. FILL items following a data type other than BYTE, WORD, LONG, QUAD, or INTEGER cannot end with a percent sign.
    • FILL% indicates integer fill. FILL$ indicates string fill. The =int-exp clause specifies the number of bytes to be moved for string FILL items.
    • Rep-cnt specifies the number of FILL items to be moved. Table 3-1 describes FILL item format and storage allocation.
    • In the applicable formats of FILL, (rep-cnt) represents a repeat count, not an array subscript. FILL (n) represents n elements, not n + 1.
  • You cannot use an expression or function reference as a move-item.

Remarks

  • Before a MOVE FROM statement can execute, the file associated with chnl-exp must be open and there must be a record in the record buffer.
  • A MOVE statement neither transfers data to or from external devices, nor invokes OpenVMS Record Management Services (RMS). Instead, it transfers data between user areas. Thus, a record should first be fetched with the GET statement before you use a MOVE FROM statement, and a MOVE TO statement should be followed by a PUT or UPDATE statement that writes the record to a file.
  • MOVE FROM transfers data from the record buffer to the move-item.
  • MOVE TO transfers data from the move-item to the record buffer.
  • The MOVE statement does not affect the record buffer's size. If a MOVE statement partially fills a buffer, the rest of the buffer is unchanged. If there is more data in the variable list than in the buffer, HP BASIC signals "MOVE overflows buffer" (ERR=161).
  • Each MOVE statement to or from a channel transfers data starting at the beginning of the buffer. For example:


    MOVE FROM #1%, I%, A$ = I%
    

    In this example, HP BASIC assigns the first value in the record buffer to I%; the value of I% is then used to determine the length of A$.
  • If a MOVE statement operates on an entire array, the following conditions apply:
    • HP BASIC transfers elements of row and column zero (in contrast to the MAT statements).
    • The storage size of the array elements and the size of the array determine the amount of data moved. A MOVE statement that transfers data from the buffer to a longword integer array transfers the first four bytes of data into the first element (for example, (0,0)), the next four bytes of data into element (0,1), and so on.
  • If the MOVE TO statement specifies an explicit string length, the following restrictions apply:
    • If the string is equal to or longer than the explicit string length, HP BASIC moves only the specified number of characters into the buffer.
    • If the string is shorter than the explicit string length, HP BASIC moves the entire string and pads it with spaces to the specified length.
  • HP BASIC does not check the validity of data during the MOVE operation.

Example


MOVE FROM #4%, RUNS%, HITS%, ERRORS%, RBI%, BAT_AVERAGE

MOVE TO #9%, FILL$ = 10%, A$ = 10%, B$ = 30%, C$ = 2%

NAME...AS

The NAME...AS statement renames the specified file.

Format

NAME file-spec1 AS file-spec2


Syntax Rules

  • File-spec1 and file-spec2 must be string expressions.
  • There is no default file type in file-spec1 or file-spec2. If the file to be renamed has a file type, file-spec1 must include both the file name and the file type.
  • If you specify only a file name, HP BASIC searches for a file with no file type. If you do not specify a file type for file-spec2, HP BASIC names the file, but does not assign a file type.
  • File-spec2 can include a directory name but not a device name. If you specify a directory name with file-spec2, the file will be placed in the specified directory. If you do not specify a directory name, the default is the current directory.
  • File version numbers are optional. HP BASIC renames the highest version of file-spec1 if you do not specify a version number.

Remarks

  • If the file specified by file-spec1 does not exist, HP BASIC signals "Can't find file or account" (ERR=5).
  • If you use the NAME...AS statement on an open file, HP BASIC does not rename the file until it is closed.
  • You cannot use the NAME...AS statement to move a file between devices. You can only change the directory, name, type, or version number.

Example


$ Directory USER$$DISK:[BASIC_PROG]
Directory USER$$DISK:[BASIC_PROG]

FIRST_PROG.BAS;1
Total of 1 file.
$ BASIC

HP BASIC V3.4
Ready

NAME "FIRST_PROG.BAS" AS "SECOND_PROG.BAS"
Ready

EXIT

$ Directory USER$$DISK:[BASIC_PROG]

Directory USER$$DISK:[BASIC_PROG]

SECOND_PROG.BAS;1

Total of 1 file.

NEXT

The NEXT statement marks the end of a FOR, UNTIL, or WHILE loop.

Format

NEXT [ num-unsubs-var ]


Syntax Rules

  • Num-unsubs-var is required in a FOR...NEXT loop and must correspond to the num-unsubs-var specified in the FOR statement.
  • Num-unsubs-var is not allowed in an UNTIL or WHILE loop.
  • Num-unsubs-var must be a numeric, unsubscripted variable.

Remarks

Each NEXT statement must have a corresponding FOR, UNTIL, or WHILE statement or HP BASIC signals an error.


Example


PROGRAM calculating_pay
DECLARE INTEGER no_hours, &
        SINGLE weekly_pay, minimum_wage
minimum_wage = 3.65
no_hours = 40
WHILE no_hours > 0
  INPUT "Enter the number of hours you intend to work this week";no_hours
  weekly_pay = no_hours * minimum_wage
  PRINT "If you worked";no_hours;"hours, your pay would be";weekly_pay
NEXT
END PROGRAM

Output


Enter the number of hours you intend to work this week? 35
If you worked 35 hours, your pay would be 127.75
Enter the number of hours you intend to work this week? 23
If you worked 23 hours, your pay would be 83.95
Enter the number of hours you intend to work this week? 0
If you worked 0 hours your pay would be 0

NOECHO

The NOECHO function disables echoing of input on a terminal.

Format

int-var = NOECHO (chnl-exp)


Syntax Rules

Chnl-exp must specify a terminal.


Remarks

  • If you specify NOECHO, HP BASIC accepts characters typed on the terminal as input, but the characters do not echo on the terminal.
  • The NOECHO function is the complement of the ECHO function; NOECHO disables the effect of ECHO and vice versa.
  • NOECHO always returns a value of zero.

Example


DECLARE INTEGER Y,      &
        STRING pass_word
Y = NOECHO(0)
INPUT "Enter your password";pass_word
IF pass_word = "DARLENE" THEN PRINT "Confirmed"
Y = ECHO(0)

Output


Enter your password?
Confirmed

NOMARGIN

The NOMARGIN statement removes the right margin limit set with the MARGIN statement for a terminal or a terminal-format file.

Format

NOMARGIN [ #chnl-exp ]


Syntax Rules

Chnl-exp is a numeric expression that specifies a channel number associated with a file. It must be immediately preceded by a number sign (#).


Remarks

  • When you specify NOMARGIN, the right margin is set to 132.
  • Chnl-exp, if specified, must be an open terminal-format file or a terminal.
  • If you do not specify a channel, HP BASIC sets the margin on the controlling terminal to 132.
  • The NOMARGIN statement applies to the specified channel only while the channel is open. If you close the channel and then reopen it, HP BASIC uses the default margin of 72.

Example


OPEN "EMP.DAT" FOR OUTPUT AS #1
NOMARGIN #1
   .
   .
   .

NUM

The NUM function returns the row number of the last data element transferred into an array by a MAT I/O statement.

Format

int-var = NUM


Syntax Rules

None


Remarks

  • NUM returns a value of zero if it is invoked before HP BASIC has executed any MAT I/O statements.
  • For a two-dimensional array, NUM returns an integer specifying the row number of the last data element transferred into the array. For a one-dimensional array, NUM returns the number of elements entered.
  • The value returned by the NUM function is an integer of the default size.

Example


OPEN "STU_ACCT" FOR INPUT AS #2
DIM stu_rec$(3,3)
MAT INPUT #2, stu_rec$
PRINT "Row count =";NUM
PRINT "Column number =";NUM2

Output


Row count = 1
Column number = 1

NUM2

The NUM2 function returns the column number of the last data element transferred into an array by a MAT I/O statement.

Format

int-var = NUM2


Syntax Rules

None


Remarks

  • NUM2 returns a value of zero if it is invoked before HP BASIC has executed any MAT I/O statements or if the last array element transferred was in a one-dimensional list.
  • The NUM2 function returns an integer specifying the column number of the last data element transferred into an array.
  • The value returned by the NUM2 function is an integer of the default size.

Example


OPEN "STU_ACCT" FOR INPUT AS #2
DIM stu_rec$(3,3)
MAT INPUT #2, stu_rec$
PRINT "Row count =";NUM
PRINT "Column number =";NUM2

Output


Row count = 1
Column number = 1

NUM$

The NUM$ function evaluates a numeric expression and returns a string of characters in PRINT statement format, with leading and trailing spaces.

Format

str-var = NUM$ (num-exp)


Syntax Rules

None


Remarks

  • If num-exp is positive, the first character in the string expression is a space. If num-exp is negative, the first character is a minus sign (--).
  • The NUM$ function does not include trailing zeros in the returned string. If all digits to the right of the decimal point are zeros, NUM$ omits the decimal point as well.
  • When num-exp is a floating-point variable and has an integer portion of 6 decimal digits or less (for example, 1234.567), HP BASIC rounds the number to 6 digits (1234.57). If num-exp has 7 decimal digits or more, HP BASIC rounds the number to 6 digits and prints it in E format.
  • When num-exp is from 0.1 to 1 and contains more than 6 digits, HP BASIC rounds it to 6 digits. When num-exp is smaller than 0.1, HP BASIC rounds it to 6 digits and prints it in E format.
  • If num-exp is an integer variable, the maximum number of digits in the returned string is as follows, depending on the data type of num-exp:

    Type Maximum Digits
    Byte 3
    Word 5
    Longword 10
    Quadword 19
  • If num-exp is a DECIMAL value, the returned string can have up to 31 digits.
  • The last character in the returned string is a space.

Example


DECLARE STRING number
number = NUM$(34.5500/31.8)
PRINT number

Output


 1.08648

NUM1$

The NUM1$ function changes a numeric expression to a numeric character string without leading and trailing spaces and without rounding.

Format

str-var = NUM1$ (num-exp)


Syntax Rules

None


Remarks

  • The NUM1$ function returns a string consisting of numeric characters and a decimal point that corresponds to the value of num-exp. Leading and trailing spaces are not included in the returned string.
  • The NUM1$ function returns a maximum of the following number of significant digits:
    • 3 for BYTE integers
    • 5 for WORD integers
    • 6 for SINGLE and SFLOAT floating-point numbers
    • 10 for LONG integers
    • 19 for QUAD integers
    • 16 for DOUBLE floating-point numbers
    • 15 for GFLOAT and TFLOAT floating-point numbers
    • 33 for HFLOAT and XFLOAT floating-point numbers
    • 31 for DECIMAL numbers
      Alpha BASIC does not support HFLOAT.
  • The returned string does not use E-format notation.

Example


DECLARE STRING number
number = NUM1$(PI/2)
PRINT number

Output


1.5708

ON ERROR GO BACK

Under certain conditions, an ON ERROR GO BACK statement executed in a subprogram or DEF function transfers control to the calling program.

Note

The ON ERROR GO BACK statement is supported for compatibility with other versions of BASIC. For new program development, it is recommended that you use WHEN blocks.

Format



Syntax Rules

The ON ERROR GO BACK statement is illegal inside a protected region or within an attached or detached handler. Use the EXIT HANDLER statement instead.


Remarks

  • If there is no error outstanding, execution of an ON ERROR GO BACK statement causes subsequent errors to return control to the calling program's error handler.
  • If there is an error outstanding, execution of an ON ERROR GO BACK statement immediately transfers control to the calling program's error handler.
  • By default, DEF functions and subprograms resignal errors to the calling program.
  • The ON ERROR GO BACK statement remains in effect until the program unit completes execution, until HP BASIC executes another ON ERROR statement, or until HP BASIC enters a protected region.
  • An ON ERROR GO BACK statement executed in the main program is equivalent to an ON ERROR GOTO 0 statement.
  • If a main program calls a subprogram named SUB1, and SUB1 calls the subprogram named SUB2, an ON ERROR GO BACK statement executed in SUB2 transfers control to SUB1's error handler when an error occurs in SUB2. If SUB1 also has executed an ON ERROR GO BACK statement, HP BASIC transfers control to the main program's error handling routine.
  • For current program development, see the WHEN ERROR statement.
  • It is not recommended that you mix ON ERROR statements with protected regions in the same program unit. For more information, see the HP BASIC for OpenVMS User Manual.

Example


IF ERR = 11
   THEN
        RESUME err_hand
   ELSE
        ON ERROR GO BACK
END IF

ON ERROR GOTO

The ON ERROR GOTO statement transfers program control to a specified line or label in the current program unit when an error occurs under certain conditions.

Note

The ON ERROR GOTO statement is supported for compatibility with other versions of BASIC. For new program development, it is recommended that you use WHEN blocks.

Format



Syntax Rules

  • You cannot specify an ON ERROR GOTO statement within a protected region or handler.
  • Target must be a valid HP BASIC line number or label and must exist in the same program unit as the ON ERROR GOTO statement.
  • If an ON ERROR GOTO statement is in a DEF function, target must also be in that function definition.

Remarks

  • HP BASIC transfers program control to a specified line number or label under two conditions:
    • If an error occurred outside a protected region of a WHEN block
    • If an error occurred within the protected region of a WHEN block and was propagated by the handler associated with the WHEN block
  • Execution of an ON ERROR GOTO statement causes subsequent errors to transfer control to the specified target.
  • The ON ERROR GOTO statement remains in effect until the program unit completes execution or until HP BASIC executes another ON ERROR statement.
  • HP BASIC does not allow recursive error handling. If a second error occurs during execution of an error-handling routine, control passes to the HP BASIC error handler and the program stops executing.
  • For current program development, see the WHEN ERROR statement.
  • It is not recommended that you mix ON ERROR statements with protected regions within the same program unit. For more information, see the HP BASIC for OpenVMS User Manual.

Example


SUB LIST (STRING A)
DECLARE STRING B
ON ERROR GOTO err_block
OPEN A FOR INPUT AS FILE #1
Input_loop:
   LINPUT #1, B
   PRINT B
   .
   .
   .
   GOTO Input_loop
err_block:
   IF (ERR=11%)
   THEN
      CLOSE #1%
      RESUME done
   ELSE
      ON ERROR GOTO 0
   END IF
done:
END SUB


Previous Next Contents Index