Const for EndOfLine


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

complains with the same message…

will not work
CR is a variable and a CONST cannot be made from a constant/literal and a variable
It can ONLY be made from other constants or literals

So you could define a dynamic constant that is global - kEOL that has a setting for macOS Windows & Linux
Only thing is that it is hard to get the right characters into that using cut & paste

OR you do something like

   #if TargetmacOS or TargetLinux
       const kEOL = &u0A
   #elseif TargetWindows
       const kEOL = &u0D + &u0A
  Const kKi  = "A Nice String" + kEOL

If only the compiler was smart enough to realise that in your example Norm there is no code between the declaration and assignment of the string variable and the creation of the constant…

You are fortunate enough to know what literal is. is… search elsewhere.

For a home developer IDE, a better definition is awaited (wasn’t it the API2 goal to do things easier ?) in the LR.

As far as I understand, Const can hold a value that exists before compiling, not at running time.

So, no variable protection against low memory troubles. *

The method loads from a source (so fixed at Method run time / unknow value at compile time) folder that holds magazine cover scans.

Unfortunately, Const does not works there.

So, this remove many of the uses.

At last, I removed all Const and declare them as Dim (Xojo 2015r1).

Because I do use them only to put data in a TextArea, I was thinking naively that a Const was the way to go.

The whole was to build an html text file from magazine cover scans (where the Magazne Name, Price, Release date, Main Story, Total Pages… are in the name).

It tooks me less time to write the code to build the html than to realize was in a dead end and changed Const to Dim.

I also add to the project a method to resize the covers to 250 pixels and now I have75 % of a description html text document who needs only to complete the ToC to be finished.

  • One day, I copied the names of a bunch of files and pasted it nto a TextArea (application running in the IDE).
    I was surprised to get strings that are NOT in any of the files names :frowning: After a simple checking, I was in low (very low) memory conditions (My Recent Items Sub-Menu disappeared from the Apple Menu, go figure).

Consider the two lines below:

  Const Tab As String = Chr(9) // Does not Compile
  Const Tab As String = &u09   // Compiles OK

From my point of view, in both cases, Tab will hold ASCII 9 value.
But the Compiler does not think so.

And, in your code, you can use Chr(9) or &u09 without trouble at all ;-:slight_smile:
Go figure

[quote=“Emile, post:3, topic:1525”]

  Const Tab As String = Chr(9) // Does not Compile
  Const Tab As String = &u09   // Compiles OK

While they look or seem like they should be similar they are not
Chr(9) is a function call and cannot be used to create a constant (a value unambiguously known at compile time)
&u09 IS completely and unambiguously known at compile time

Its a subtle distinction and there are means to make the first work - they just dont exist in Xojo’s compiler

Or if the compiler could evaluate that expression at compile time so it would just work
That could work for a number of functions and would alleviate a lot of angst about this

where should i define the const???
and where can i use the kEOL??

The problem with trying to define kEOL as a global const is that you can NOT use &u0D or any other notation like that for the const ( see feedback://showreport?report_id=51506 )
You’d have to define it using copy & paste of the various end of line characters as text (so they would appear to be empty)

When I have needed this I define kEOL right above where I am going to use it
Since its a local constant there is no issue with defining it multiple times and it CAN be used in the definition of other constants
But it does lead to multiple definitions spread all over

thanks norman