Whilst delivering a REXX course on 6th August 2002, one of the exercises related to testing a one character string entered in response to Say instruction. The test was to determine the attributes of the character entered. One of the delegates asked if there was a potentially better way of addressing the problem, and the code below a proposal.

A subroutine was created at the end of the main routine and the built-in function VERIFY was used to validate the character.

/* ---- REXX demonstration of VERIFY Built-in Function ---- */
Say 'Enter a string of characters to be tested'
Parse Pull input_string .
len = LENGTH(input_string)
i = 1
Do While i < (len + 1)
   Select
     When DATATYPE(SUBSTR(input_string,i,1),L) = 1 Then Do
       Say SUBSTR(input_string,i,1) "is lower case"
       Call case_test
       End
     When DATATYPE(SUBSTR(input_string,i,1),U) = 1 Then Do
       Say SUBSTR(input_string,i,1) "is upper case"
       Call case_test
       End
     When DATATYPE(SUBSTR(input_string,i,1),W) = 1 Then
       Say SUBSTR(input_string,i,1) "is numeric"
     Otherwise
       Say SUBSTR(input_string,i,1) "is a special character."
   End
   i = i + 1
End
Say "Number of letters entered was" len
Exit 0                                   /* leave program */
/*
   ---- Test for vowel or consonant ----
*/
case_test:
  If VERIFY(SUBSTR(input_string,i,1),"aAeEiIoOuU",M,1) \= 0 Then
     Say SUBSTR(input_string,i,1) "is a vowel"
     Else
     Say SUBSTR(input_string,i,1) "is a consonant"
Return

End of Topic.

Copyright © KMS-IT Limited 2002