LISTGET Example


Example:

 

*

 

 

.Define the Objects

.

 

 

EDIT1

EDITTEXT

 

EDIT2

EDITTEXT

 

STAT1

STATTEXT

 

STAT2

STATTEXT

 

RADIO1

RADIO

 

BUTTON1

BUTTON

 

VAR1

VAR

@

COLL1

COLLECTION

 

INDEX

FORM

"1"

VARTYPE

INTEGER

4

TYPEDESC

DIM

10

*

 

 

.Fill the Collection

.

 

 

 

LISTINS

COLL1,EDIT1,EDIT2,STAT1,STAT2:

 

 

RADIO1,BUTTON1

*

 

 

.Retrieve each item from the Collection

.

 

 

 

LOOP

 

 

LISTGET

VAR1,INDEX,COLL1

 

UNTIL

OVER

*

 

 

.Display the object type

.

 

 

 

TYPE

VAR1,VARTYPE

 

SWITCH

VARTYPE

 

CASE

1584

 

MOVE

"EDITTEXT",TYPEDESC

 

CASE

4144

 

MOVE

"STATTEXT",TYPEDESC

 

CASE

3632

 

MOVE

"RADIO",TYPEDESC

 

CASE

304

 

MOVE

"BUTTON",TYPEDESC

 

DEFAULT

 

 

MOVE

"UNKNOWN",TYPEDESC

 

ENDSWITCH

 

.

 

 

 

DISPLAY

"Item ",INDEX," is a ",TYPEDESC

*

 

 

.Next Item

.

 

 

 

INCR

INDEX

 

REPEAT

 

*

 

 

.All items displayed

.

 

 

 

KEYIN

"Continue... ",INDEX

 

 

 

*

 

 

.Delete the second edittext (EDIT2) and the

. second stattext (STAT2) object

.

 

 

 

LISTDEL

COLL1,EDIT2,STAT2

*

 

 

.Retrieve the new count of items

.

 

 

 

LISTCNT

INDEX,COLL1

 

KEYIN

"The collection now contains ":

 

 

*DV,INDEX," items.",INDEX;

.

 

 

 

STOP

 

 

This example program creates a collection of six objects using the LISTINS instruction. LISTGET then progresses through the objects in the collection. As each object is retrieved, the TYPE instruction determines the object type. Once all six objects are displayed, the LISTDEL instruction deletes two objects from the collection. The deletion is verified through the use of the LISTCNT instruction.

 



PL/B Language Reference