#72557 - 2003-01-13 11:39 AM
Trying to shorten a script
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
I don't have a problem with the code for the script (unless someone sees a problem) I made for our techs to use. I was wondering if there was an easier way to do the script below, rather than make 15 CASE SELECTs?
Thanks in advance, Z.
code:
CLS ? "Choisi le numéro de l'application que vous voulez vérifier ou Q pour quitter?" ? box(3,0,13,57,"") AT (4,1) "(1) Appli1" AT (4,16) "(2) Appli2" AT (4,40) "(3) Appli3" AT (6,1) "(4) Appli4" AT (6,16) "(5) Appli5" AT (6,40) "(6) Appli6" AT (8,1) "(7) Appli7" AT (8,16) "(8) Appli8" AT (8,40) "(9) Appli9" AT (10,1) "(10) Appli10" AT (10,16) "(11) Appli11" AT (10,40) "(12) Appli12" AT (12,1) "(13) Appli13" AT (12,16) "(14) Appli14" AT (12,40) "(15) Appli15" ?? ? "Votre Choix (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,Q) : " GETS $answer SELECT CASE $answer = "" ? "Vous devez choisir un des applicatoins disponibles" sleep (2) goto APPLI_VERIF CASE $answer = "1" ? "Vous avez choisi de vérifier Appli1, merci de patienter" sleep (2) goto Appli1 CASE $answer ="2" ? "Vous avez choisi de vérifier Appli2, merci de patienter" sleep (2) goto Appli2 CASE $answer = "3" ? "Vous avez choisi de vérifier Appli3, merci de patienter" sleep (2) goto Appli3 CASE .... CASE .... CASE .... CASE $answer = "Q" ? "Vous avez choisi de reprendre l'inventaire utltérieurement" ? "Merci de patienter un instant" sleep (2) GOTO START ENDSELECT
|
|
Top
|
|
|
|
#72562 - 2003-01-14 12:01 AM
Re: Trying to shorten a script
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
Thanks for the quick replies to one and all.
I am using Kix4.12. The real problem is that writting scripts is not one of my fortés, I can get them to do what I want most of the time, but I don't necessarily take the shortest path to do them.
Thx, Z.
|
|
Top
|
|
|
|
#72563 - 2003-01-14 12:20 AM
Re: Trying to shorten a script
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You could try something like:
code:
CLS ? "Choisi le numéro de l'application que vous voulez vérifier ou Q pour quitter?" ? box(3,0,13,57,"") AT (4,1) "(1) Appli1" AT (4,16) "(2) Appli2" AT (4,40) "(3) Appli3" AT (6,1) "(4) Appli4" AT (6,16) "(5) Appli5" AT (6,40) "(6) Appli6" AT (8,1) "(7) Appli7" AT (8,16) "(8) Appli8" AT (8,40) "(9) Appli9" AT (10,1) "(10) Appli10" AT (10,16) "(11) Appli11" AT (10,40) "(12) Appli12" AT (12,1) "(13) Appli13" AT (12,16) "(14) Appli14" AT (12,40) "(15) Appli15" ?? ? "Votre Choix (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,Q) : " GETS $answer $RC=execute("Gosub 'Appli" + $answer + "'")
[ 13. January 2003, 12:21: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#72565 - 2003-01-13 04:26 PM
Re: Trying to shorten a script
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
Why is "GOTO" a no no? Would you replace it with a GOSUB? I don't see how I can do it another way without using GOTO. The GOSUB command doesn't seem like a viable solution. I've now modified my script to do a
code:
GOTO $answer
On a side note, can I use the execute command to call on another kix script?
thx, Z.
|
|
Top
|
|
|
|
#72568 - 2003-01-13 04:33 PM
Re: Trying to shorten a script
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
I'd use "execute()" to call a UDF?
I'd write a UDF if I could, unfortunately if you have ever seen my coding, you'd realize that writting code is not something I do overly well. I can get my scripts to do what they need to do, but usually I take the long road to get there.
I've tried to understand UDFs but I don't know if there's something I'm just missing in getting how they work. I've looked at other people's UDFs but I can't figure them out for the life of me. Just when I think I get it, I realize I don't.
Thx, Z.
|
|
Top
|
|
|
|
#72570 - 2003-01-13 04:50 PM
Re: Trying to shorten a script
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
in short :
a UDF is a costum kixtart function which can be making the impossible work (functions not build in) ... one can compare UDFs with GOSUBs, nearly the same but not exactly : UDFs are more elegant ...
To help you out with your current case, how about this :
code:
break on
CLS ? "Choisi le numéro de l'application que vous voulez vérifier ou Q pour quitter?" ?
$Choices = "","app1.exe","app2.exe","app3.exe","app4.exe","app5.exe","app6.exe", "app7.exe","app8.exe","app9.exe","app10.exe","app11.exe","app12.exe", "app13.exe","app14.exe","app15.exe","app16.exe"
box(3,0,13,57,"") AT (4,1) "(1) Appli1" AT (4,16) "(2) Appli2" AT (4,40) "(3) Appli3" AT (6,1) "(4) Appli4" AT (6,16) "(5) Appli5" AT (6,40) "(6) Appli6" AT (8,1) "(7) Appli7" AT (8,16) "(8) Appli8" AT (8,40) "(9) Appli9" AT (10,1) "(10) Appli10" AT (10,16) "(11) Appli11" AT (10,40) "(12) Appli12" AT (12,1) "(13) Appli13" AT (12,16) "(14) Appli14" AT (12,40) "(15) Appli15" ?? ? "Votre Choix (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,Q) : " GET $answer
if $answer = "q" quit() endif
if val($answer) > 0 and val($answer) < 16 $ = RunChosenApp(val($answer)) ;call the running UDF with the number of choice as parameter endif
get $
function RunChosenApp($n) $ = execute("run '$Choices[$n]'") ; translated : run 'appn.exe' endfunction
This won't fit exactly to your need but you'll get the picture
_________________________
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1046 anonymous users online.
|
|
|