READ$ function

Purpose

Retrieve string data from a local DATA list.

Syntax

value$ = READ$(n%)

Remarks

The READ$ function is used to retrieve a specified string data item from a local DATA list, and returns the data in string format.  READ$ offers a simple technique for random-access of local DATA.

n%

An integer-class expression, constant, or variable, which specifies an index position in the local DATA list.  n% = 1 for the first data item, n% = 2 for the second, and so on.  READ$ accesses the DATA statements in the order in which they appear in the source program, from left to right.

If n% is greater than DATACOUNT, READ$ returns an empty string, but no run-time error occurs.

value$

READ$ places the DATA string into value$.

If the target DATA statement is enclosed in quotes, READ$ preserves any leading or trailing spaces that it may contain; otherwise, READ$ trims leading and trailing spaces and returns a trimmed string.  See DATA for more information on data item formatting.

If numeric data needs to be stored in DATA statements and retrieved with READ$, the VAL function can be used to convert the return values from READ$ into numeric values.

Restrictions

There is a limit of 64 Kilobytes and 16384 separate data items per Sub or Function, and it is not possible to read DATA from outside of the scope of current Sub or Function.  Restrictions apply to using colon and underscore characters in DATA statements - see DATA for more information.

See also

DATA, DATACOUNT

Example

' The following returns the day of the week string.

FUNCTION WeekDayName$(BYVAL DayNum%)

  IF DayNum% < 1 OR DayNum% > DATACOUNT THEN

    WeekDayName$ = ""

  ELSE

    WeekDayName$ = READ$(DayNum%)

  END IF

  DATA Sun, Mon, Tue, Wed, Thu, Fri, Sat

END FUNCTION