Copyright 2008 Shoptalk Systems

READ one or more comma delimited variable names

Description:

This fetches the next strings and/or numeric values from DATA statements in a program. The READ statement will fetch enough items to fill the variable names the programmer specifies. The values fetched will be converted to fit the variables listed (string, numeric or array references).

Example:

  'read the numbers and their descriptions
  while desc$ <> "end"
    read desc$, value
    print desc$; " is the name for "; value
  wend
  'here is our data
  data "one hundred", 100, "two", 2, "three", 3, "end", 0
  end

You can also read numeric items:

  'read the numbers and their descriptions
  while desc$ <> "end"
    read desc$, value$
    print desc$; " is the name for "; value$; ", length="; len(value$)
  wend
  'here is our data
  data "one hundred", 100, "two", 2, "three", 3, "end", 0
  end

Error Handling

If you try to read more DATA items than are contained in the DATA lists, the program will halt with an error. Notice that in the examples above, an "end" tag is placed in the DATA and when it is reached, the program stops READing DATA. This is an excellent way to prevent errors from occurring. If an end tag or flag of some sort is not used, be sure that other checks are in place to prevent the READ statement from trying to access more DATA items than are contained in the DATA statements.

See also DATA, RESTORE