make a constant that is equal to chr(9) i.e. tab ?

in a module, how do I define a constant that is equal to chr(9) so the tab char ?
I can do it in a method that returns a chr(9)
but when you deal with text import or export you need a lot of chr(9) or chr(13)
and it would compile far more efficient if I can have a constant instead of a method call

how do you handle this in your programs ?
thanks.

did you try pasting one into the field?

I normally use a global property tab where I assign the encodings.ASCII.chr(9) value at start.

I usually assign it where I need it in a method. Here’s a quick way:

const kTab = &u9

Thanks Kem.

That’s how I do it too, but it is not a string, it’s an Integer. The OP was about having Chr(9) as a constant.

That is a string literal.

Eli, the structure “&uNNNN” creates a string literal of the Unicode code point NNNN. This must be provided as hex, not decimal, so the letter “Z” is &u5A.

but what you CANNOT do is define it as a CONSTANT via the drop down menu

Const kTab=&u9
msgbox str(ascb(kTab)) ‘’ this show 9 like it should

but if you define it in the side panel (under Constants)… it returns 38
because the constant became “&u9” not &u9 (ie… quotes were added)

I just use a computed property to return the value…

[quote=161188:@Dave S]but what you CANNOT do is define it as a CONSTANT via the drop down menu

Const kTab=&u9
msgbox str(ascb(kTab)) ‘’ this show 9 like it should

but if you define it in the side panel (under Constants)… it returns 38
because the constant became “&u9” not &u9 (ie… quotes were added)[/quote]

I thought about that. The issue is automatic assignment. The IDE takes anything that looks like a string as … a string. The IDE could indeed take &u09 as chr(9) but then how would it deal with “&universe” as a string ? Maybe it would be nice to be able to signal Xojo that a constant is a unicode point, maybe as &&u09 ?

In the meantime, it does not seem out of this world to enter &u09 instead of Tab…

This module has kTab as a global constant = ChrB(9).

Just import the module into your project.

[quote=161195:@Wayne Golding]This module has kTab as a global constant = ChrB(9).

Just import the module into your project.[/quote]

This is brilliant, but I need to understand. How did you come up with this line ?

#tag Constant, Name = kTab, Type = String, Dynamic = False, Default = \"\\t", Scope = Public

In particular, how is Default = \"\\t" built ? What is the relationship between \t and chr(9) ? Is it akin to word’s ^t ? What if I want with the same principle to create an EndOfLine with &u0D+&u0A ?

Michel I hacked the project with a hex editor. There’s a whole bunch of stuff you just can’t do with the IDE that is perfectly possible.

I have a project that writes data driven listbox subclass modules so I can design my listboxes (column widths, alignment, headings etc.) in a wysiwig fashion. Saves me hours of getting the look right and automates the repetitive tasks. This is an example of a generated listbox.

I got it. I exported Wayne’s module to XML, and found that the default value was there as byte. So I was able to add kRet, which is &u0D+&u0A :

<Constant> <ItemName>kTab</ItemName> <Compatibility></Compatibility> <Visible>1</Visible> <TextEncoding>134217984</TextEncoding> <ItemType>0</ItemType> <ItemDef><Hex bytes="1">09</Hex></ItemDef> <ItemFlags>0</ItemFlags> </Constant> <Constant> <ItemName>kRet</ItemName> <Compatibility></Compatibility> <Visible>1</Visible> <TextEncoding>134217984</TextEncoding> <ItemType>0</ItemType> <ItemDef><Hex bytes="2">0D0A</Hex></ItemDef> <ItemFlags>0</ItemFlags> </Constant>

I used that to add EndOfLIne to XojoiOSWrapper https://github.com/Mitchboo/XojoiOSWrapper
:slight_smile:

[quote=161202:@Wayne Golding]Michel I hacked the project with a hex editor. There’s a whole bunch of stuff you just can’t do with the IDE that is perfectly possible.
[/quote]
Unsupported & if it breaks … well …

Use &u09[quote=161205:@Michel Bujardet]I got it. I exported Wayne’s module to XML, and found that the default value was there as byte. So I was able to add kRet, which is &u0D+&u0A :

[code]
I used that to add EndOfLIne to XojoiOSWrapper https://github.com/Mitchboo/XojoiOSWrapper
[/quote]

Again - if it breaks steps to reproduce creating the file would be requested & “Oh I hacked it in” might turn into “not a bug” since you can’t recreate this from the IDE

Thanks Kem, good to know. I’ve never used &uNNNN for constants created in the IDE, because I only just figured out now, that the data type needs to be Integer.

Constant Name: Tab
Default value: &u9
Type: Number

TextArea1.Text = Tab + "abc"   // will show "        abc"

Constant Name: Tab
Default value: &u9
Type: String

TextArea1.Text = Tab + "abc"   // will show "&u9abc"

Well I’ll be… Would you look at that? Nice catch!

It looks like you can use that trick for a single character but not multiple characters. Within code though, this works:

const kEOL = &u0D + &u0A

I can’t see a way to reproduce that in the constant editor.

hum … nice to see my original question was not as trivial as it could appear !