How do I create a constant comprising of Chr(10) + Chr(13)? I am working with the serial port interacting with an embedded device and it uses Chr(10) + Chr(13) as command terminators.
A constant can’t be an expression, however you could write a method that simply returns those characters.
I was hoping I could add those characters to the string editor somehow of the constant editor and avoid the overhead of a method call. Guess I’ll do the method call.
isn’t that endofline.windows ?
I believe Windows is Chr(13) + Chr(10)
Why not a string variable then?
The variable is in a module, can I initialize it from the module? i.e., I use the module in many projects would hate to forget to initialize it on app start.
Given windows and DOS use 0D0A as line terminators , how sure are you that 0A0D is what you should be sending?
The only sources of data that used 0A0D that I know of are BBC Micro and RISC machines.
And as Markus points out, if you have a variable in a module, you can initialise it in the app.open event.
Write code. Simple app copies the bytes to the clipboard. Then just paste into the constant editor.
Will such a constant retain its value when saved to all of Xojo’s file formats, Thom?
I’d be very scared if it did not.
Not so sure myself given that the IDE is not designed for this, is it, thus requiring you clever workaround?
Jemery, the “cleanest” solution would be to use a function or a computed property and use code like this inside:
static lfcr as String = chr(10)+chr(13)
This way, the value will only be “calculated” once, saving a little of time. Nothing big, though.
You could also copy the code from an editor that supports it and paste it into a string constant.
Or create a dummy constant, save the prj as XML and find the constant in there, then edit it like this (note “ItemDef”):
(Yay, Xojor3 still writes “ItemName” twice)
Or save in VCP format and edit it there:
#tag Constant, Name = LFCR, Type = String, Dynamic = False, Default = \"\
\\r", Scope = Public
@Jeff, yes, it is Chr(10) + Chr(13)… Code is working great, and results are clearly separated by Chr(10) + Chr(13).
@Thomas, I like your LFCR in the VCP solution. I do everything in VCP already. Thanks!
If the IDE cannot store a perfect 1:1 replica of whatever it was given, that is a very serious bug. But the good news is that this works.
Indeed! How I miss an inline command in Xojo. Can’t understand why it’s not included yet.