Const does not allow "String" + EndOfLine?

The code line below generates an error:

I started with:

  Const kKi  = "A Nice String" + EndOfLine

Then

  Dim CR As String = EndOfLine
  Const kKi  = "A Nice String" + CR

But not that one:

Const kKi = “A Nice String” + “CR” // But I do not care

The error string is:
This is a constant; its value can’t be changed

Must I use a standard variable (everytime I want an EndOfLine in it) ?

EndOfLine is a function in this usage so that won’t work.

Instead use a literal value:

Const kTest = "A Nice String" + &u0A
2 Likes

Strange behavior, but thank you for the solution
&u0A for all platforms ?
or &u0A + &u0D for some ?

As usual, I wanted to follow my way:

  Dim CR As String = &u0A
  Const kKi  = "A Nice String" + CR

complains with the same message…

You cannot modify a constant at runtime. Instead try this:

Const CR = &u0A
Const kKi  = "A Nice String" + CR

This works because both are constants so it can be resolved at compile time.

You can also do something like this:

#if TargetWindows then
  const EOL as string = &u0D + &u0A
#else
  const EOL as string = &u0A
#endif
const kKi as string = "A Nice String" + EOL
1 Like

Two good bets in a row:

THANK YOU GUYS !

I keep Kem code, but removed Const and use Dim instead.

It tooks me less time to achieve the Method than to start it until I asked this question ;-:slight_smile:

Time for dinner !