11.04.2013 Views

UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

In the following example, the program statement searches the entire array, FILMS,<br />

element by element, for the literal string “BATMAN.” If the search is successful,<br />

UniData assigns the location of the element to the variable NDX. If UniData does not<br />

find the string, it sets NDX to the location of the last value plus 1, and it executes the<br />

STOP command. The LOCATE command performs the search on the attribute level.<br />

LOCATE "BATMAN" IN FILMS SETTING NDX ELSE STOP<br />

Because the LOCATE statement compares the entire element (including associated<br />

lower-level elements), a match will not be successful on either of the following<br />

arrays:<br />

or<br />

"CARMEN":@AM:"BATMANII":@AM:"JAWS"<br />

"CARMEN":@AM:"BATMAN":@VM:"KEATON":@VM:"DEVITO"@VM:"CARREY<br />

":@AM:"JAWS"<br />

In the next example, the program segment prints “BATMAN IS IN POSITION 2 IN<br />

THE ARRAY”:<br />

FILMS = "CARMEN":@AM:"BATMAN":@AM:"JAWS"<br />

LOCATE "BATMAN" IN FILMS SETTING NDX ELSE<br />

PRINT "NOT FOUND"<br />

STOP<br />

END<br />

PRINT "BATMAN IS IN POSITION ":NDX:" IN THE ARRAY"<br />

In the next example, the program segment searches the array FILMS, starting at<br />

attribute 2, value 2, for the contents of the variable DEVITO. UniData assumes the<br />

array elements are in ascending order and left-justified.<br />

LOCATE DEVITO IN FILMS BY "AL" SETTING NDX THEN<br />

PRINT "THIS TITLE IS IN THE LIBRARY"<br />

END ELSE<br />

PRINT "TITLE NOT FOUND, TRY AGAIN."<br />

END<br />

When executed on the following array, DEVITO is located in position 3 in the array<br />

at the value level, and UniData executes the first PRINT statement:<br />

"CARMEN":@AM:"BATMAN":@VM:"KEATON":@VM:"DEVITO"@VM:"CARREY<br />

":@AM:"JAWS"<br />

LOCATE 1-423

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!