# Control array index numbers

**URL:** <https://forum.xojo.com/t/control-array-index-numbers/76436>\
**Category:** General\
**Created:** [July 7, 2023, 7:00pm UTC](https://forum.xojo.com/t/control-array-index-numbers/76436 "2023-07-07T19:00:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Allen](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e19adc/32.png) [@John\_Allen](https://forum.xojo.com/u/John_Allen)\
**Post date:** [July 7, 2023, 7:00pm UTC](https://forum.xojo.com/t/control-array-index-numbers/76436/1 "2023-07-07T19:00:12Z")

</div>

The documentation says

Remember, because Control Sets are not arrays if you remove a control in the middle of the Control Set you will get a _hole_ in the index values. For example if you have four items in a Control Set they will initially have index values of 0, 1, 2, 3. If you remove index 2 then you will have three items in the Control Set with index values of 0, 1, 3. Index value 2 will be Nil.

Is this actually correct?  
I have dynamically created a set of checkboxes. Then one or more were optionally deleted. Based on the documentation I expected holes in the list but deleting seems to close the gaps, no holes in the index sequence. Makes life a lot simpler but …

---

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [July 8, 2023, 7:10am UTC](https://forum.xojo.com/t/control-array-index-numbers/76436/3 "2023-07-08T07:10:13Z")

</div>

I always relied on the fact that gaps are indeed removed in this case (since 20 years of programming with “Xojo”). No idea why the documentation says otherwise.

---

<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:** [July 8, 2023, 12:31pm UTC](https://forum.xojo.com/t/control-array-index-numbers/76436/4 "2023-07-08T12:31:18Z")

</div>

The gaps are not automatically removed if you delete elements at design time. They never have been. In this case, if you ignore the documentation, you can introduce bugs.

![image](https://forum.xojo.com/uploads/default/original/2X/9/96eadeea968c1dc688ff94282332b5313910a06f.png)

---

<div class="post-metadata">

**Author:** ![John\_Allen](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e19adc/32.png) [@John\_Allen](https://forum.xojo.com/u/John_Allen)\
**Post date:** [July 8, 2023, 1:35pm UTC](https://forum.xojo.com/t/control-array-index-numbers/76436/5 "2023-07-08T13:35:02Z")

</div>

Ok, that seems to make sense. Delete them in the IDE and remaining instances are not renumbered. Delete in code and gaps are closed up.

I’ll try and remember that.

---

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [July 8, 2023, 3:25pm UTC](https://forum.xojo.com/t/control-array-index-numbers/76436/6 "2023-07-08T15:25:58Z")

</div>

> [@Anthony\_G\_Cyphers](#):
>
> In this case, if you ignore the documentation, you can introduce bugs.

Perhaps the documentation could make it clearer that it’s about design time.

> [@John\_Allen](#):
>
> Delete them in the IDE and remaining instances are not renumbered. Delete in code and gaps are closed up.

So, if one both deletes some in the IDE and then deletes others in code, we can assume the gaps will be removed entirely.

---

<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:** [July 8, 2023, 3:38pm UTC](https://forum.xojo.com/t/control-array-index-numbers/76436/7 "2023-07-08T15:38:49Z")

</div>

Assume what the documentation says but test for yourself. Be aware that the behavior could change to match the documentation or vice-versa.

---

<div class="post-metadata">

**Author:** ![Paul\_Chance](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_chance/32/22072_2.png) [@Paul\_Chance](https://forum.xojo.com/u/Paul_Chance)\
**Post date:** [July 8, 2023, 4:15pm UTC](https://forum.xojo.com/t/control-array-index-numbers/76436/8 "2023-07-08T16:15:56Z")

</div>

One of the “facts (programming) life” I have to remind my friends about is, just because something’s in print, that doesn’t make it true. Quantum Physics aside, everything happens at a point in time and what was true at one time, may not be true later. So I always suggest that when coding for an action to happen, test it to make sure what you think happened, actually did happen.

My naivete was exposed in College Calculus class where the answers to odd numbered quiz questions (at the end of the chapter) were given in the back of the textbook. Except some of them were wrong! How could they print a calculable answer incorrectly? If it’s in print, it may be true; it may not.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [July 9, 2023, 12:51am UTC](https://forum.xojo.com/t/control-array-index-numbers/76436/9 "2023-07-09T00:51:11Z")

</div>

> [@Arnaud\_N](#):
>
> So, if one both deletes some in the IDE and then deletes others in code, we can assume the gaps will be removed entirely.

Not quite. If you have a gap already, that gap will be preserved. Eg, suppose your indexes are

1, 2, 4, 5, 6, 8, 9

If you remove 5, that run of indexes will be closed up, but only that sequence. You get

1, 2, 4, 5, 8, 9

6 was moved down to 5 to close the gap you just created, but the pre-existing gaps are not crossed.

---

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [July 9, 2023, 6:22am UTC](https://forum.xojo.com/t/control-array-index-numbers/76436/10 "2023-07-09T06:22:32Z")

</div>

> [@Anthony\_G\_Cyphers](#):
>
> Assume what the documentation says but test for yourself. Be aware that the behavior could change to match the documentation or vice-versa.

Then, IMO, that’s not worth reading the documentation in the first place. Just try.

> [@Tim\_Hare](#):
>
> Not quite. If you have a gap already, that gap will be preserved.

Thanks; that’s actually what I wanted to know. (sometimes I don’t have time to launch the IDE right now to test).
