# R3 problem with RecentItems class LastIndex and Clear

**URL:** <https://forum.xojo.com/t/r3-problem-with-recentitems-class-lastindex-and-clear/67625>\
**Category:** Getting Started\
**Created:** [December 27, 2021, 7:01pm UTC](https://forum.xojo.com/t/r3-problem-with-recentitems-class-lastindex-and-clear/67625 "2021-12-27T19:01:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [December 27, 2021, 7:01pm UTC](https://forum.xojo.com/t/r3-problem-with-recentitems-class-lastindex-and-clear/67625/1 "2021-12-27T19:01:33Z")

</div>

Desktop and both Mac and Windows  
I am having a problem on R3 with Clearing my RecentItems Classes. I have “ **LsstRowIndex** ” reported as 4 but the actual COUNT is 6.  
The line in the Clear method which throws an OutOfBounds is below

```auto
While me.RecentItemsQueue.LastIndex > -1
  me.parent.RemoveMenuAt me.RecentItemsQueue.LastIndex// Here
Wend

```

I don’t know what else to include but code.

[https://www.dropbox.com/sh/4n7us65t9y4dew4/AABxxDvQm7YNOp8FnHdQi2-va?dl=0](https://www.dropbox.com/sh/4n7us65t9y4dew4/AABxxDvQm7YNOp8FnHdQi2-va?dl=0)

In the open for the app ( mine is in the preferences file)

```auto
MaxRecents = val(pArrayFile(rowcnt))//rowcnt = 6 App.pLimit (Protected)
Recentitems = new RecentitemsManager(FileOpenRecent)

```

In the open a file

`RecentItems.Add(f)`

As the property declaration (Mine is in the App property list)

`Recentitems As RecentitemsManager`

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [December 27, 2021, 8:09pm UTC](https://forum.xojo.com/t/r3-problem-with-recentitems-class-lastindex-and-clear/67625/2 "2021-12-27T20:09:00Z")

</div>

> [@Arthur\_Gabhart](#):
>
> ```auto
> While me.RecentItemsQueue.LastIndex > -1
> me.parent.RemoveMenuAt me.RecentItemsQueue.LastIndex// Here
> Wend
> 
> ```

You do understand that you’re not removing things from the RecentItemsQueue when you call RemoveMenuAt right? That loop probably fails on the second call because the array and the menu no longer have the same number of items in it.

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [December 27, 2021, 8:57pm UTC](https://forum.xojo.com/t/r3-problem-with-recentitems-class-lastindex-and-clear/67625/3 "2021-12-27T20:57:59Z")

</div>

Thanks.  
The previous line was

```auto
While me.RecentItemsQueue.LastIndex > -1
  me.parent.Remove me.RecentItemsQueue.Pop
Wend

```

Which translates to (I think)

```auto
While me.RecentItemsQueue.LastIndex > -1
  me.parent.RemoveAt(me.RecentItemsQueue.LastIndex) me.RecentItemsQueue.Pop
Wend

```

But the compiler doesn’t like it And nor do I.

Do you have a suggextion?

---

<div class="post-metadata">

**Author:** ![Emily-Elizabeth\_Howard](https://forum.xojo.com/user_avatar/forum.xojo.com/emily-elizabeth_howard/32/14415_2.png) [@Emily-Elizabeth\_Howard](https://forum.xojo.com/u/Emily-Elizabeth_Howard)\
**Post date:** [December 27, 2021, 9:40pm UTC](https://forum.xojo.com/t/r3-problem-with-recentitems-class-lastindex-and-clear/67625/4 "2021-12-27T21:40:24Z")

</div>

If you are removing all the items, try removing the first item every time through the loop (if there are six items, then remove the first item six times to get rid of all the items)

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [December 27, 2021, 10:29pm UTC](https://forum.xojo.com/t/r3-problem-with-recentitems-class-lastindex-and-clear/67625/5 "2021-12-27T22:29:56Z")

</div>

My confusion is I cannot use the line below  
`me.parent.RemoveMenuAt 0`

as that also throws an OutOfBounds  
If I remove from the queue that doesn’t mean it is removed from the parent.  
Using this code

```auto
While me.RecentItemsQueue.LastIndex > 0
  me.parent.RemoveMenuAt me.RecentItemsQueue.FirstIndex
Wend

```

I still have 4 items in the queue after iterating 4 times.

I also prefer the class I have over the exsmple.

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [December 28, 2021, 12:26am UTC](https://forum.xojo.com/t/r3-problem-with-recentitems-class-lastindex-and-clear/67625/6 "2021-12-28T00:26:07Z")

</div>

> [@Arthur\_Gabhart](#):
>
> ```auto
> While me.RecentItemsQueue.LastIndex > -1
> me.parent.RemoveAt(me.RecentItemsQueue.LastIndex) me.RecentItemsQueue.Pop
> Wend
> 
> ```

Try it like this:

```auto
While me.RecentItemsQueue.LastIndex > -1
    me.parent.RemoveAt(me.RecentItemsQueue.LastIndex) 
    me.RecentItemsQueue.Pop
Wend

```

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [December 28, 2021, 12:41am UTC](https://forum.xojo.com/t/r3-problem-with-recentitems-class-lastindex-and-clear/67625/7 "2021-12-28T00:41:59Z")

</div>

Thanks for doing this for me. I’d left my house thinking I needed to two lines and came home to experiment. (Not really a challenging experiment, but…)

Charles Yeamons wrote a good class, but it’s hard to modernize.

Edit: slight modification

```auto
me.parent.RemoveMenuAt(me.RecentItemsQueue.LastIndex) 
me.RecentItemsQueue.RemoveAt(me.RecentItemsQueue.LastIndex)

```
