Using constants

OK that’s clear, thanks

I still have a Constant headache. I did everything kevin g suggested and started small with cr and tab to be chr(13) and chr(9) but Xojo interpreted these as the literal characters chr(13) and chr(9) and all the strings I was constructing became gibberish.

Since I couldn’t see how to get the values I wanted accepted, I left the values blank and included cr = chr(13) and tab = chr(9) at the start of my winMain opening event, but that was not accepted since cr and tab were defined as constants and couldn’t be changed from being nothing to being something.

I wanted to do the right thing but have given up defeated and reverted to setting cr and tab and other constants as strings rather than waste any more time.

You are trying to create constants that need to be calculated. Unfortunately, string constants defined in the navigator have to be literals and cannot involve any kind of calculation / function call.

The way I solve this limitation is to fake a constant using a property added to the module and then have a method in the module that initialises it.

This works as long as you don’t do anything stupid such as changing the value of the property elsewhere in your code.

Again…

A constant that needs to be computed is a computed property
Add a string variable CR
Right click and convert to Computed Property

Then change the contents of the Get

and comment out the Set

1 Like

Beware of Xojo constants in a copy/paste, Xojo does not honor “inserted” constants as constants. LOL. I had a headache when I discovered that Xojo by itself changed all my chr(10) to chr(13) so I needed to fix my constant later replacing those chr(13) by chr(10) again in a variable before using it.

Why do you want to define constants that are already there? Check out EndOfLine.

1 Like

He talked about cr and tab; he probably does not saw EndOf Line, but the question is still valid (for Tab).

1 Like