# How did he not know it?

**URL:** <https://forum.xojo.com/t/how-did-he-not-know-it/72091>\
**Category:** General\
**Created:** [September 3, 2022, 6:02pm UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091 "2022-09-03T18:02:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![KarenA](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/c89c15/32.png) [@KarenA](https://forum.xojo.com/u/KarenA)\
**Post date:** [September 3, 2022, 6:02pm UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091/1 "2022-09-03T18:02:31Z")

</div>

The obvious answer would be it is not documentation, but is it?

In any case that is something I have known for many years, though I don’t recall how i learned it…

Not only can you assign one constant to another , but as being able to do that assignment implies, you can also assign a constant expression to a constant.

Try:

```auto
Const X as Integer = 3
Const Y as Integer = X + 1
Const Z as Integer = X + Y

MsgBox "Y = " +Str(Y) + " Z = " +Str(Z)

```

And you get what you would expect

-Karen

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [September 3, 2022, 6:12pm UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091/2 "2022-09-03T18:12:32Z")

</div>

I imagine most Assemblers can do similar. Certainly the ones I used, 40 and more years ago, could do such as:

```auto
A EQU 27
B EQU 33
C EQU (A+B)/2

```

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [September 3, 2022, 6:20pm UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091/3 "2022-09-03T18:20:02Z")

</div>

I knew that you could define and use constants that way in methods, that’s not uncommon, I didn’t know that you could define constants that way as members of classes or modules. Which is part of why I’m surprised I never tried it.

If you were aware that this could be done, that’s great. Wish you’d told me two decades ago. 😀

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [September 3, 2022, 6:41pm UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091/4 "2022-09-03T18:41:14Z")

</div>

And just to illustrate what we’re talking about, as the code you provided above appears to be from a method, this is the implementation that surprised me:

 ![image](https://forum.xojo.com/uploads/default/original/2X/0/0705a357b5723042b419672b198fe61897943956.png)

 ![image](https://forum.xojo.com/uploads/default/original/2X/c/cadd5a79e0c3ec49ad65ea82897369d0a13520fe.png)

### Update

You can download the project outlined in the article [here](https://graffitisuite.com/downloads/ms_25546.zip).

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [September 3, 2022, 7:07pm UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091/5 "2022-09-03T19:07:43Z")

</div>

I do believe we’re talking about different things as constants defined via the inspector cannot be evaluated as you say they can in the first post here. For instance:

 ![image](https://forum.xojo.com/uploads/default/original/2X/b/b535d4f971e47a9e4e3ab22f3d0f0cc4e351d30e.png)

Results in a Syntax Error:  
 ![image](https://forum.xojo.com/uploads/default/original/2X/2/269fbfa1102eadeddb3ce44795c29325bd877fa0.png)

---

<div class="post-metadata">

**Author:** ![KarenA](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/c89c15/32.png) [@KarenA](https://forum.xojo.com/u/KarenA)\
**Post date:** [September 3, 2022, 7:33pm UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091/6 "2022-09-03T19:33:33Z")

</div>

I may be wrong but I thought one time it did … but I could be misremembering. It’s not something I played with much, but now that you mention it I vaguely recall something along those lines being changed a good while back too…

After 20+ years of using the product it all blends together !

-Karen

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [September 3, 2022, 7:37pm UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091/7 "2022-09-03T19:37:21Z")

</div>

There’s an open ticket about this behavior. There’s some interesting bits in the comments of the ticket.

[#55502 - Adding a constant to a class cant use an expression while one in code can](https://tracker.xojo.com/xojoinc/xojo/-/issues/55502)

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [September 3, 2022, 9:17pm UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091/8 "2022-09-03T21:17:43Z")

</div>

Currently, there’s an software design adage that says something like that:

If an attribution can be expressed entirely by constants and literals, it should be done; if not, if it can be expressed using an immutable (like final), it must be done; only after those options exhausted you must think in using mutables (variables).

const \> final \> var

---

<div class="post-metadata">

**Author:** ![Gilles\_Plante](https://forum.xojo.com/user_avatar/forum.xojo.com/gilles_plante/32/667_2.png) [@Gilles\_Plante](https://forum.xojo.com/u/Gilles_Plante)\
**Post date:** [September 3, 2022, 10:35pm UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091/9 "2022-09-03T22:35:37Z")

</div>

I would like to know from Xojo if that behavior was planed or it’s a bug. @Paul_Lefebvre, can you explain please.

If that was not planned and it’s fixed, the code will break in many applications.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [September 4, 2022, 12:10am UTC](https://forum.xojo.com/t/how-did-he-not-know-it/72091/10 "2022-09-04T00:10:24Z")

</div>

> [@Gilles\_Plante](#):
>
> I would like to know from Xojo if that behavior

What behavior? Case #55502? It’s a “current limitation that should not occur”, in case of missing a better label, a bug label could be used to classify it.

It won’t break codes as codes trying to use it today just don’t compile it accusing a syntax error. But being able to compile it, is a desired feature.
