OS/2 Procedures Language 2/REXX


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


DATATYPE( )


When attempting to perform arithmetic on data entered from the keyboard, 
you can use the DATATYPE( ) function to check that the data is valid. 
This function has several forms.  The simplest form returns the word, NUM, 
if the expression inside the parentheses ( ) is accepted by the 
interpreter as a number that can be used in the arithmetic operation. 
Otherwise, it returns the word, CHAR. For example: 

The value of DATATYPE(56) is NUM
The value of DATATYPE(6.2) is NUM
The value of DATATYPE('$5.50') is CHAR
In the following procedure, DATATYPE.CMD, the internal REXX function, 
DATATYPE( ), is used and the user is asked to keep typing a valid number 
until a correct one is typed. 

/* Using the DATATYPE( ) Function */
DO UNTIL datatype(howmuch) = 'NUM'
 SAY 'Enter a number'
 PULL howmuch
  IF datatype (howmuch) = 'CHAR'
   THEN
   SAY 'That was not a number.  Try again!'
END
SAY 'The number you entered was' howmuch
EXIT

If you want the user to type only whole numbers, you could use another 
form of the DATATYPE( ) function: 

DATATYPE (number, whole)

The arguments for this form are: 
   o  number -  refers to the data to be tested. 
   o  whole -  refers to the type of data to be tested.  In this example, 
      the data must be a whole number. 
 
 This form returns a 1 if number is a whole number, or a 0 otherwise.   

Inf-HTML End Run - Successful