View previous topic :: View next topic
|
Author |
Message |
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
Hi guys,
Just got the question , i have the panel , in this panel have several option. There will be option said when you tpye X , the progrom will exit. How to do that ? Thanks
Code: |
Option_
0 DEFAULTS
1 PREPARE
2 TSO
X EXIT - Exit primary menu |
My code :
Code: |
uname=ARG(1)
ADDRESS ISPEXEC
"DISPLAY PANEL (panel2)"
rc=4
DO WHILE rc <> 0
SELECT
WHEN c=1 THEN DO
rc=REXX4()
END
WHEN C=2 THEN DO
rc=rexx1()
end
WHEN C=x THEN DO
?????????????????????
END
OTHERWISE
rc=4
END
END
END |
|
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
Unsurprisingly, the keyword is exit. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2593 Location: Silicon Valley
|
|
|
|
Quote: |
Unsurprisingly, the keyword is exit. |
You can use any method to exit the DO loop. As another alternative, you can use a LEAVE instruction. See the rexx reference for more information.
Sorry to nitpick your code...
But the example assumes the user types X in the panel then presses Enter. The user should also be able to merely press F3, in which case your code should check for RC=8.
And it is not clear, but I think you want the DISPLAY to be inside of the DO loop so that it allows the user to serially select any of the options and when done, then press F3. As it is currently written, the panel is only shown once. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
Pedro wrote: |
Quote: |
Unsurprisingly, the keyword is exit. |
You can use any method to exit the DO loop. As another alternative, you can use a LEAVE instruction. See the rexx reference for more information. |
I believe that the TS wanted to exit the progrom (sic), not just the DO loop.
And, yes, that code is not just not right, it's not even wrong. Presumably the TS will have a number of other questions to ask as he tests it. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Akatsukami wrote: |
And, yes, that code is not just not right, it's not even wrong. Presumably the TS will have a number of other questions to ask as he tests it. |
jackzhang75, here are a few rules you should adopt before coming back with more questions:
1. Don't be lazy with variables names: To name the option field 'c' is bad. Later you will need a counter and you will call it 'c' as well, and you will end up with unreadable and undebuggable code.
How to give a long name to a 1 char field in the panel ?
Code: |
)BODY
+Option:_Z+
)INIT
.ZVARS = '(OPTION)' |
As easy as that. There must be as many names in .ZVARS as you have Z's in the body.
2. Be consistent with names: if option is 1 you run rexx4, if option is 2 you run rexx1 ? Just add rexx2 for option 0 and you're all setup for a big mess.
3. Keep it simple: in 13 lines I do more than you do in 20 (although I didn't check my code)
Code: |
uname=ARG(1)
Address ISPEXEC
Do Forever
"DISPLAY PANEL(panel2)"
If RC <> 0 Then Leave
Select
When Option = '0' Then Call Process_Opt_Defaults
When Option = '1' Then Call Process_Opt_Prepare
When Option = '2' Then Call Process_Opt_TSO
Otherwise "SETMSG MSG(ISPP195)"
End
End
Exit |
|
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Ooops, on my way back from lunch I just remembered I forgot this line:
Code: |
When Option = 'X' Then Leave
|
Why do I use LEAVE and not EXIT ?
Sometimes I do some stuff before and/or after the main process:
Code: |
Call Prolog
Do Forever
...
End
Call Epilog
Exit |
With LEAVE the "epilog" will be executed. Not with EXIT. |
|
Back to top |
|
|
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
Firstly, i want to thanks you all to provided me really nice suggestion and solution.
Now i use MARSO solution , it works very well. I can press X and exit the progrom. To Marso , i not sure what's your first suggestion (code ) exactly means?
Code: |
)BODY
+Option:_Z+
)INIT
.ZVARS = '(OPTION)' |
Second question as Akatsukami said, i want to also press F3 to exit the progrom not just type X , how to make it ?
Code: |
uname=ARG(1)
ADDRESS ISPEXEC
DO FOREVER
"DISPLAY PANEL (panel2)"
SELECT
WHEN C='1' THEN REXX1()
WHEN C='2' THEN REXX2()
WHEN C='X' THEN LEAVE
OTHERWISE SETMSG MSG(ISPP195)
END
END
EXIT |
Thanks |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
Do not use FOREVER, but rather WHILE (RC¬=0). Also, I recommend that the DISPLAY service be invoked at the end of the DO loop, instead of at the beginning. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2593 Location: Silicon Valley
|
|
|
|
Quote: |
Do not use FOREVER, but rather WHILE (RC¬=0). |
Based on the code in Jack's latest post, I think it should be: While (RC = 0).
rather than 'not equal'. |
|
Back to top |
|
|
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
hi , i got another question.
The same progrom , but i add another call for a function , it seems after running the funciton , the progrom just stop there not continue to display the panel , why? Thanks
MYARG=userid()
Code: |
call [b]Function [/b]
ADDRESS ISPEXEC
DO FOREVER
"DISPLAY PANEL (panel2)"
SELECT
WHEN C ='1' THEN REXX1()
WHEN C ='2' THEN REXX2()
WHEN C ='X' THEN LEAVE
OTHERWISE "SETMSG MSG(ISPP195)"
END
END
exit
Function :
XXXXXXXXXXXXXXXXX
Return MYARG |
|
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1787 Location: Bloomington, IL
|
|
|
|
You recognize that you should either invoke function as
Code: |
variable = function() |
or by
Code: |
call function
variable = rc |
? |
|
Back to top |
|
|
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
Hi AKASTSUJAmi, Now i can call the function ,and the function working fine . My problem was after runing the function , the code seems not continue to next step and the progrom just exit with RC=0 .. I don't know what's wrong? |
|
Back to top |
|
|
jackzhang75
Active User
Joined: 09 Jun 2014 Posts: 125 Location: US
|
|
|
|
hi , i found the problem, something wrong in my function , I take off
ADDRESS ISPEXEC
"CONTROL ERRORS RETURN"
SIGNAL ON HALT
SIGNAL ON FAILURE
SIGNAL ON SYNTAX
ADDRESS TSO
in function , it works.. dont's know why |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2593 Location: Silicon Valley
|
|
|
|
When you have this:
Code: |
SIGNAL ON HALT
SIGNAL ON FAILURE
SIGNAL ON SYNTAX |
You need to provide a subroutine called HALT, a subroutine called FAILURE, and a subroutine called SYNTAX.
My guess is that you have some kind of problem and rexx gives up because it cannot find the subroutine that you said you were going to provide. I am surprised there are no other messages.
The second line of your program should be:
And show us the trace.
note: the spelling is program, not progrom |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
You must have something like this in your panel:
That is why you check for the value of 'C' in your rexx program.
If you want to give a better name to your variable, you have two options:
- just give a better name:
but now the user can type up to 3 characters in the field. Sometimes it's not important, sometimes it is.
Use .ZVARS:
followed by
Code: |
)INIT
.ZVARS = '(OPTION)' |
Each variable named 'Z' will be in fact named after what is found in the .ZVARS.
That way, you keep the correct field length and you give a real name to the variable.
There is a better explanation and example here. |
|
Back to top |
|
|
|