Page 1 of 1

No constant chr() ?

Posted: Wed Jun 25, 2003 6:55 pm
by Karbon
So you can't do this?

Code: Select all

#CRLF = chr(13) + chr(10)
Seems to come out to the number 10

Probably a simple reason that I'm not thining about :-)

Re: No constant chr() ?

Posted: Wed Jun 25, 2003 7:06 pm
by GPI
CHR() is a function, so you can't use it with constants.

Posted: Wed Jun 25, 2003 7:07 pm
by Karbon
Gotcha. Thanks!

Posted: Wed Jun 25, 2003 7:19 pm
by freak
Not quite:

If you use Chr() with a constant inside like Chr(13), this is replaces by
a chr(13) character on compilation time. So Chr() is only included as a
function, if you use variables inside it.

This makes Chr() a constant thing, however, it can't be used with constants directly.

Something like:
SetGadgetText(#Gadget, "Hello"+Chr(10)+"World")

Will be optimized, so the whole "Hello"+Chr(10)+"World" expression will
be stored as one string in the exe, because it only contains constant strings
and Chr() with a fixed value inside. So on runtime, this needs no Function
call, and no String addition.

So kind of constant then, just not a #Constant :wink:

Timo