No constant chr() ?

Just starting out? Need help? Post your questions and find answers here.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

No constant chr() ?

Post 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 :-)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: No constant chr() ?

Post by GPI »

CHR() is a function, so you can't use it with constants.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Gotcha. Thanks!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
Post Reply