SELECT Examples


Example 1:

 

DOW

FORM

1

DVAR1

INIT

"A"

.

 

 

  

CLOCK

WEEKDAY,DOW

.

 

 

  

DISPLAY

"The current day of the week is ";

.

 

 

  

SELECT

USING DOW

  

WHEN

"1"

  

DISPLAY

"Sunday";

  

WHEN

"2"

  

DISPLAY

"Monday";

  

WHEN

"3"

  

DISPLAY

"Tuesday";

  

WHEN

"4"

  

DISPLAY

"Wednesday";

  

WHEN

"5"

  

DISPLAY

"Thursday";

  

WHEN

"6"

  

DISPLAY

"Friday";

  

WHEN

"7"

  

DISPLAY

"Saturday";

  

DEFAULT

 

  

DISPLAY

"Invalid";

  

ENDSELECT

 

.

 

 

  

DISPLAY

"."

 

This example retrieves the current day of the week and uses the SELECT statement to display its name.

 

Example 2:

 

DVAR1

INIT

"A"

DVAR2

INIT

"8"

.

 

 

  

LOOP

 

  

KEYIN

"Enter First Character :",*UC,DVAR1,*N:

  

  

"Enter Second Character:",*UC,DVAR2

  

SELECT

USING DVAR1, DVAR2

.

 

 

  

WHEN

"A" THRU "Z", "A" THRU "Z"

  

DISPLAY

"Both characters alpha"

  

WHEN

"A" THRU "Z", "0" THRU "9"

  

DISPLAY

"First character alpha & second number."

  

WHEN

"0" THRU "9", "A" THRU "Z"

  

DISPLAY

"First character number & second alpha."

  

WHEN

"0" THRU "9", "0" THRU "9"

  

DISPLAY

"First character number & second number."

  

DEFAULT

 

  

DISPLAY

"DEFAULT..TRY AGAIN A-Z or 0-9."

.

 

 

  

ENDSELECT

 

  

REPEAT

 

 

The example allows the user to enter two characters from the keyboard. The characters are then evaluated using the SELECT statement and their type is displayed.

 

Example 3:

 

V

FORM

2

.

 

 

  

SELECT

USING V

  

WHEN

"1" OR "2" OR "3"

  

DISPLAY

*HD,"Switch V=1 OR 2 OR 3: V=",V

  

WHEN

"4"

  

DISPLAY

*HD,"Switch V=4: V=",V

  

WHEN

"5"

  

DISPLAY

*HD,"Switch V=5: V=",V

  

WHEN

"6"

  

DISPLAY

*HD,"Switch V=6: V=",V

  

ENDSELECT

 

 

The example show the use of multiple selection criteria in a WHEN statement.

 



PL/B Language Reference SEARCH Examples SET Examples