READV Statement

The READV statement permits a single attribute of a file item to be read and placed into a dynamic array variable.

Format

READV var FROM [filevar,] item-ID, attr#  [THEN statements1] [ELSE statements2]

Parameter(s)

var

Assigns to var the string value of the attribute, in dynamic array form.

FROM [filevar,] item-ID, attr#

Assigns var the string value of attribute attr# in item-ID in the file which was opened as filevar.

item-ID is an expression evaluating to an item-ID.

attr# is a valid expression which must evaluate to an attribute number in the specified item. If the attribute number is zero then it returns the number of attributes in the item being read. This is useful when processing items of different sizes, where a different algorithm is required for very large items.

If filevar is not specified, the default file variable is used, which is the file most recently opened without a file variable assignment. If the specified item-ID or attribute number does not exist, var is assigned the value of the null string ("").

THEN statements1

Executes statements1 if the attribute is read successfully.

ELSE statements2

Executes statements2 if the item cannot be found or if the attribute cannot be read.

Description

Before a file may be accessed in a READV statement, it must be opened with an OPEN statement or an error will occur at run-time. See OPEN Statement for more information.

In mvBASIC, there are also READ, READU, and READVU statements available. The READVU statement sets an item update lock on the item before reading the attribute. The READ statement reads the entire file item, and the READU statement sets an item update lock on the file item before reading it.

See READU Statement, READV Statement and READV Statement for more information.

Example

In this application, the file represented by CUSTFILE contains the name, address, and phone number of each customer. The phone number is kept in Attribute 6 of each item. To retrieve only the customer's phone number, the READV statement is used to capture Attribute 6.

PRINT "ENTER CUSTOMER ID : " :    

INPUT ID   

READV PHONE FROM CUSTFILE,ID,6 ELSE

   PRINT "ERROR!"    

   STOP  

END  

PRINT ID , PHONE

See Also

Statement and Function Reference