Page 1 of 1 1
Topic Options
#2920 - 2000-05-16 12:54 AM Problems with IF
Anonymous
Unregistered


I'm new to kixtart and I'm having trouble with the IF command.
I'd like to verify if variable1 is different from a specific string or variable2 is empty or variable3 is empty.
This seems easy but doesn't work the way I do it:
-- start --
break on
if $call <> "yes" or $s=0 or $d=0
? "syntaxe : ..."
exit 0
endif
? "Either the $$call variable is set to yes or the required parameters"
? "($$s and $$d) are set"
-- end --

The sctipt is supposed to be lauched either by setting the variable $call=yes (or $call="yes") or by setting the variables $s and $d to anything but NULL

Why doesn't it work?


Incindentally, I'd gladly accept any difficult sample script.

------------------

Top
#2921 - 2000-05-15 01:24 PM Re: Problems with IF
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
jltari:

You might want to try some reverse logic ...

code:

break on

if ($call or ($d and $s)) and ($call="yes")
else
?"syntax error"
exit
endif

? "Either the $$call variable is set to yes or the required parameters"
? "($$s and $$d) are set"


Actually - this shouldn't work - but it does !

Shawn.

[This message has been edited by Shawn (edited 15 May 2000).]

Top
#2922 - 2000-05-15 01:59 PM Re: Problems with IF
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Gang:

I was looking for a good excuse to post this observation ... not sure if this is a known bug in KiX32 for Windows NT or not ...

Try the following script at your own risk. Kiddies - don't try this at home unless you have parental supervision ...

Sample script called "echo.kix" ...

--- 8< ---
break on
?'The value of $$var is "$var"'
exit
--- 8< ---

Call it from the command line like this...

kix32 echo.kix $var="hello world"

you get ...

The value of $var is "hello world"

Easy-peesie eh ?

Now - call it like this ...

kix32 echo.kix $var

KiX32 spins off into an infinite loop (ala 100% CPU land) and generally barfs like it just ate a bad tuna sandwich !

Another example for ALWAYS putting a "BREAK ON" statement in all your scripts ( at least until it's ready for production ).

Shawn.

[This message has been edited by Shawn (edited 15 May 2000).]

Top
#2923 - 2000-05-16 03:30 AM Re: Problems with IF
Anonymous
Unregistered


Thank you. I didn't think of using parentheses, they weren't mentioned in the doc.

Top
#2924 - 2000-05-16 05:55 AM Re: Problems with IF
Anonymous
Unregistered


It looks like one can't use the IF command with an empty variable, is that right?

Top
#2925 - 2000-05-16 09:31 AM Re: Problems with IF
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Gang:

KiX needs some type checking functions like isstring(), isnumeric() and isassigned(). Does anyone agree ?

I mean - it's not so much a problem with internal variables (assigned/used inside the script) - but when you have a script that excepts command line arguments - it would be nice to know what your dealing with.

To demonstrate the need for these functions and for those who like a challenge - here's today's excerise ...

Write a script called "echo.kix" that excepts one command line argument - namely $arg - and echo's out to the screen EXACTLY what was specified on the command line !

Example:

c:\> kix32 echo.kix $arg=(whatever)
echo: $arg=(whatever)
c:\>

hint: The challenge is to differenciate between the following...

$arg="" from $arg=0 from $arg= and $arg not specified

As well, make sure you check for that pesky $arg

Maybe by doing this - we can establish some rules on how KiX treats unassigned variables and how we can more effectively type check !

Shawn.

p.s. Has anybody been able to duplicate that $arg "bug" or am I just being a doh-head ?

Top
#2926 - 2000-05-16 10:33 AM Re: Problems with IF
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Yes i was able to recreate the blank variable from the command line problem

only happens when you forget the "="

here is what i have found out....

1. you can't forget the = when setting a var from the command line, you get loop-o-death

2. you can't set a var to = "" from a command line, you can only do this from inside a script. Setting a var to be "" from a command line is the same as setting the var to not equal anything at all, or the default value of 0.

now here is a weird one...

use the following code "test.kix"

code:

break on
? val("$arg")
? $arg

run with the following command lines

U:\>kix32 test $arg="001"

1
1

the $arg was only set a numeric value, but...

U:\>kix32 test $arg="001a"

1
001a

$arg is now a string!

weird!

Bryce

Top
#2927 - 2000-05-16 11:08 AM Re: Problems with IF
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Bryce:

Your first example demonstrates something very interesting...

When one runs this ...

break on
$arg = "001"
? $arg
exit

one gets this ...

001

But - when one runs this ...

break on
; $arg="001" ; commented out
? $arg
exit

like this ...

kix32 test $arg="001"

one gets this ...

1

Looks like KiX does some sort of numeric string conversion but only on command line parameters !

Have we opened up a can of worms with here ?

Shawn.

[This message has been edited by Shawn (edited 16 May 2000).]

Top
Page 1 of 1 1


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

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

Generated in 0.056 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

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