Page 1 of 2 12>
Topic Options
#72557 - 2003-01-13 11:39 AM Trying to shorten a script
zdarma Offline
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
#72558 - 2003-01-13 11:42 AM Re: Trying to shorten a script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Gotos ... uhhhh ... I predict a reply from Jens (sealeopard) saying that this is no good coding practice !

Hmmmm ... what Is your KiX Version ?
_________________________



Top
#72559 - 2003-01-13 11:43 AM Re: Trying to shorten a script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you could indeed change it...

I'm not sure as I don't use goto but just do:
goto $answer
_________________________
!

download KiXnet

Top
#72560 - 2003-01-13 11:43 AM Re: Trying to shorten a script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
damn I'm slow!
_________________________
!

download KiXnet

Top
#72561 - 2003-01-13 11:48 AM Re: Trying to shorten a script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
maybe you should sleep more ?
_________________________



Top
#72562 - 2003-01-14 12:01 AM Re: Trying to shorten a script
zdarma Offline
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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#72564 - 2003-01-14 12:23 AM Re: Trying to shorten a script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Or ... instead of using a gosub as you are taking advantage of 4.12 you can pass the choice ( I would use the Application shell string) as a parameter to a custom UDF and let it run the choosen application, no ?

[ 13. January 2003, 12:25: Message edited by: jpols ]
_________________________



Top
#72565 - 2003-01-13 04:26 PM Re: Trying to shorten a script
zdarma Offline
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
#72566 - 2003-01-13 04:27 PM Re: Trying to shorten a script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
to call another kixscript use CALL
_________________________
!

download KiXnet

Top
#72567 - 2003-01-13 04:28 PM Re: Trying to shorten a script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
That'd be the CALL command ... execute() is just a way to execute kix commands / functions !

What is wrong in writing a UDF ? Could save you tons of code [Big Grin]
_________________________



Top
#72568 - 2003-01-13 04:33 PM Re: Trying to shorten a script
zdarma Offline
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. [Frown]

Thx,
Z.

Top
#72569 - 2003-01-13 04:40 PM Re: Trying to shorten a script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you should not mess up the execute in this as it has no relevance.

the current change in your code, to change the labels with the var is the most thing we can advice without seeing the whole executing code...

still, it probably would not minimize it anymore.

what comes to udfs, they are just like kixtart functions, just user made.

you use them the same way as readline() or box() or any other kix function.
only difference is that you need to add the udf-code... say definition-code... somewhere to kix to know what you want.
you don't have to know the inner working of an udf.
just how you call it and what it brings back...

think anyway that it's another lesson...
with udf, I see no way to shorten the current code...

j?
_________________________
!

download KiXnet

Top
#72570 - 2003-01-13 04:50 PM Re: Trying to shorten a script
Jochen Administrator Offline
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
#72571 - 2003-01-13 04:57 PM Re: Trying to shorten a script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
am I silly or why I don't get the picture...
why your code:
code:
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

can't be replaced with:
code:
if $answer > 0 and $answer < 16
run $choices[$answer]
endif

get $

isn't that just the same?

[ 13. January 2003, 16:58: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#72572 - 2003-01-13 06:26 PM Re: Trying to shorten a script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Because there could be a 'Q' as a correct input,too. However, I would do a SELECT-CASe statement
code:
SELECT
CASE $answer = 'q'
quit()
CASE VAL($answer) and VAL($answer)<16
RUN $choices[$answer]
CASE 1
; incorrect selection, try again
ENDSELECT

_________________________
There are two types of vessels, submarines and targets.

Top
#72573 - 2003-01-13 08:04 PM Re: Trying to shorten a script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Even better Jens ! (was hacked 5 minutes before leaving the Office)
Lonk, only because get returns a string !
_________________________



Top
#72574 - 2003-01-13 08:11 PM Re: Trying to shorten a script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And I din't even say anything about those pesky GOTOs [Big Grin]
_________________________
There are two types of vessels, submarines and targets.

Top
#72575 - 2003-01-13 08:24 PM Re: Trying to shorten a script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
ROFLMAO !

You did sit on your hands typing with nose, eh ?
_________________________



Top
#72576 - 2003-01-13 08:26 PM Re: Trying to shorten a script
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, I quess I might still argue...
will let it be...
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.073 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org