Page 1 of 1 1
Topic Options
#78321 - 2001-08-23 12:12 AM Variable types
Anonymous
Unregistered


Question:

Ik know it's bad scripting on my side but I had a scritp that used a variable filled with a 0 (type long). After a check to see if that variable matches a "string" it returns true!

$var=0
$string="string"
IF $var=$string ? "True???" ELSE ? "Untrue" ENDIF

Is this normal behavior? It had me looking for a problem for almost an hour...

Top
#78322 - 2001-08-23 12:23 AM Re: Variable types
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes.
you are comparing integer and string and their vartype does not mach.
this means that kix converts the last variable to same vartype as the first one and if you do val($string) it returns 0!

kind of weird. you can test this by setting the if statement from:
IF $var=$string

to:
IF $string=$var

and it returns untrue. in this case the first one is string and the integer is translated to string and as string 0 is 0.
if you need to match different type of variables and assure they are compared correctly you can use string type conversion:
IF "$string"="$var"

returns untrue like also:
IF "$var"="$string"

confused?


cheers,

_________________________
!

download KiXnet

Top
#78323 - 2001-08-23 12:28 AM Re: Variable types
Anonymous
Unregistered


I'd rather hit a "type mismatch"...
then again, kixscripting would have all
the irritating tendencies of full-blown
programming without the benefits.


but I got it, thanxx!

Top
#78324 - 2001-10-14 06:18 AM Re: Variable types
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

Ruud gives a complete explanation of your topic. See for his
reaction topic
http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=3&t=000201
A piece of it:
the overall type of an expression is based on the left-most operand.
....
this is described in the paragraph on expressions
Greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

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