It's quite the same and does work, or?
That's because Chr is checked at compiletime if found inside a constant-declaration, and that's what he's asking for the str()-command.
Anything that requires compilation to determine the value assigned to a constant is basically illegal (that is what variables are for). Otherwise PB would need to run the program as it was compiling it.
compileTimeSec.s = Chr(Second(Date()))
#_compiledOn = "Compiled on this second: "+compileTimeSec+"!"
So the crash reported is a bug in as much as PB doesn't report use of a variable where it shouldn't be used - it is not a bug in that PB should allow a variable there, because variables vary and are not, um constant.
For i = 1 To 20
compileTimeSec.s = Str(ElapsedMilliseconds())
#_compiledOn = "Compiled on this second: " + compileTimeSec + "!"
Debug #_compiledOn
Next i
What is this? The Debuger have no problem with this. Why?
1: Constants can only use literals or previously defined constants when assigning values.
2: Simple functions/operations such as Chr, Str, +, - and etc allowed.
3: Compiler has a hissy and spits out an error message otherwise.
If so, I agree, I would like to see this.
I wish I may, I wish I might
Get constant definitions right!
It seems to me, that it's not really the function thats in question, but the parameter.
#myconst = "text" + chr(13) + "more text"
This example passes a constant 13 to the function, and could be interpreted by the compiler with ease.
CR.L = 13
#myconst = "text" + chr(CR) + "more text"
This example passes a variable and can not be determined at compile time.
#myconst = "text" + chr(#myotherconst) + "more text"
This example also passes a constant, in theory, and since the compiler does not allow a constant to be defined multiple times, and it does not allow variables to be assigned to constants (since variables are run time only) then this should work. But remember, either the constant has to be defined earlier in the source code, or the compiler needs to catch it on a 1st pass (I don't know if pure is 1 or 2 pass compiler).
Many of the exotic examples in various posts of this thread just aren't realistic because they try to put run time elements into a constant, which defeats the purpose.
Added:
Having said all that, it should not matter whether the function is CHR or STR or ASC or anyother function, as long both the function and the paramter are pre-defined and not variable. Obviously any function to be used in this way would need to be executable by the compiler.
I would also like to add that there are a number of special case variables which could be added as pseudo constants. Date, Time, Source File Name, path, object name, user name, build#, etc. Being able to inject these items into a constant with something like a format$ function could be useful for project control.