Marked as: Normal
Hello,
Here's a little rexx script for you all to study.
The script contain these parts.
Load external function package, but only the functions we want/need.
Create a function that solve a subset of our problem
The function can be used again in another situation and still be useful, something that's important to remember during development.
/* Retrieve keystroke without wait for Enter Key */
/* Load ONLY the function we are going to use, nothing else */
/* Left the last parameter out as it's the same as the first and we don't need another alias for it */
call RxFuncAdd 'SysGetKey', 'RexxUtil'
say 'Welcome to this rexx example'
say /* Empty row */
say 'Would you like to begin? (Y/n)' /* Yes by default */
if translate( SysGetKey( 'ECHO' ) ) = 'N' then return 1; /* if No, then end right here! */
say
say 'Please enter your name...'
name = MyInputFuction( 'ECHO' ) /* Show what the user type */
say
say 'Please enter the secret password...'
pwd = MyInputFuction( 'NOECHO' ) /* Don't show what the user type, substitute with * instead */
say
say
say "Hehehe, we know "||name||"'s secret password! It's "||pwd
Return 0 /* End of script, only comments and function(s) below */
/* This is a somewhat generalized version to handle various tasks */
MyInputFuction: procedure /* Variables will stay local within function */
retval = ''
inputkey = ''
do while c2d( inputkey ) <> 13 /* End when the user hit character 13 (Enter) on the keyboard */
inputkey = SysGetKey( ARG(1) ) /* (Don't) show what the user typed */
if c2d( inputkey ) <> 13 then do
if ARG(1) = 'NOECHO' then
call charout , '*' /* Show * instead of what the user typed */
retval = retval||inputkey /* Append input key to text we'll return */
end
end
return retval