select Statement

The select statement creates an active list of item-IDs, allowing sequential access to each item in the file by use of the readnext statement.

Syntax

select {var|file.var|list.var {to list.var}}

Parameter(s)

var

Specifies a dynamic array variable.

file.var

Specifies a file variable that has been used on an open statement.

list.var  

Specifies the select list to be used.

Description

Unlike the AQL select or sselect commands, the BASIC select statement cannot have selection criteria or perform a sort. The BASIC select passes through every item in the file in hashed order.

If file.var is not specified, the default file variable is used. When used with the to clause, the item list is assigned to the specified select variable.

If an external list is already active when the program is executed, or the program performs an execute of an AQL select, sselect, qselect, or get-list, the active list is returned by the BASIC select, regardless of the passed file variable.

Example(s)

The customer file is opened and every item is selected.

open ’customer’ to customer.file else stop 201,’customer’

select customer.file

eof=0

loop

readnext ID else eof = 1

until eof do

print ID:" exists"

repeat

The customer file is selected and assigned to the list variable customer.list.

open "customer’ to customer.file else stop 201, ’customer’

select customer.file to customer.list

select customer.list to save.cust.list; * save list for later

eof=0

loop

readnext ID from customer.list else eof=1

until eof do

print ID:" exists"

repeat

The array variable, string, is treated as an active list by assigning it to the list variable, list.

string = ’1001’:char(254):’1002’:char(254):’1003’

select string to list

eol=0

loop

readnext ID from list else exit

print ID:" exists"

repeat

This example demonstrates multiple active lists in the same program. It first selects all local file pointers from the master dictionary and assigns them to the md.list list variable using select. Each file name is used to select all items in the data section.

open ’md’ to md.file else stop 201,’md’

execute ’select md with a1 = "d]"’

select md.file to md.list

loop

readnext file.name from md.list then

open file.name to temp.file then

execute ’select ’:file.name

select temp.file to temp.list

loop

readnext tempID else exit

print tempID:" in ":file.name:" exists"

while 1 do repeat

end

end else exit

until 1 do repeat

 

NOTE

Another select clears the primary and secondary lists.

This form of select causes BASIC to scan the file with each readnext.

The select and readnext statements both consume an external list if one is available. As a result, system(11) always returns 0 after one of these commands. For example:

execute "select bp sampling 5"

print system(11)

select

print system(11)

This prints 5, then 0. The external list is consumed by a BASIC variable and is then only available from FlashBASIC or BASIC.

A select list variable cannot be read or written by normal BASIC functions and statements. Access must be purely through select and readnext.