• Welcome to OS2World OLD-STATIC-BACKUP Forum.
 

News:

This is an old OS2World backup forum for reference only. IT IS READ ONLY!!!

If you need help with OS/2 - eComStation visit http://www.os2world.com/forum

Main Menu

InputKeys and a function that can do more than one thing.

Started by jep, 2008.10.01, 13:54:35

Previous topic - Next topic

jep

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


ddan

Jep, have to nitpick on this one: it bails out on me at
     5 +++   Call RxFuncAdd 'SysGetKey', 'RexxUtil';
REX0040: Error 40 running C:\temp\inputkey.cmd, line 5: Incorrect call to
routine

I already have the whole rexxutil.dll -- it's only 68K -- loaded from a
program that runs on boot-up (and of course once loaded, it stays resident
unless one goes to some trouble to drop its functions), so think that specific
function loading is best skipped, even if your purpose is education as here.
-- On the other hand, it's easy to forget that EVERY program needs to specify
loading the library because one can't be sure that it IS already loaded. REXX
just skips over if it is, so I start a program by pasting in the WHOLE .dll
loading.

No problems with the rest. Tested it because wanted to be sure that SysGetKey
includes effective sleeping while waiting for a key; however, I usually need a
loop around keyboard polling so am forced to test charin() and use syssleep.

jep

Hello,

yes, you're quite correct.

The code doesn't check if you have already loaded rexxutil, but I've also (deliberately) omitted the third param as it's mostly not needed.

It may be so that it won't work if you've loaded it previously, but about that I'm unsure.

I hope you use the version of rexxutil during boot that contain the function, and not something older without it?!

//Jan-Erik

ddan

Jep, I need the voice of experience. This is a bit off-topic, but still REXX.

I've long been puzzled by syntax of functions, can't seem to grasp why the first version below doesn't work, when it's the same form as an example (for another function) that does work (from the readrexx.txt about the newer rexxutil.dll):
Call SysStemInsert "MyStem.", 5, "New value for item 5"

Nearly all of the functions in REXX.INF are in "call function(parameter, parameter)" form, WITH parentheses "()", yet don't work for me in that form, have to be assigments like:
s= overlay('X', 'abcdef', 5)
Is that just bad example text, or am I missing a huge part of some fundamental?

==================== snip ====================
/* test */
wflc='0123456789'
rxc_n= 5
say wflc
call insert 'X', wflc, rxc_n /* doesn't do anything visible, yet no error */
   /* ^^^ and with parentheses gives an error! */
say wflc
wflc= insert('X', wflc, rxc_n) /* this works */
say wflc
exit
====================== snip ============================

jep

Hello,

The rexx language was defined that way, though some think it's inconsistent and want to change it.

Code written in Regina rexx prior to version 3.2 or similar support by default the "faulty" way you describe to call things with parenthesis. You can turn the behavior on for Regina with a setting though. There's no such thing in OS/2 rexx (unless you use/try Regina for OS/2-eCS).


Here's a little text for those of you that have difficulties to remember how and why:

It's a huge "NO-NO" to
call something()
directly with parenthesis (Would be like calling out silently! ??? ), but you can
say something()
with parenthesis, think of it as whispering instead of speaking in a normal voice.  ;)

//Jan-Erik