Unexpected OutOFBounds Exception

The code below works fine, but a folder is skipped:

// Combien d’items dans le dossier Master_FI ?
Master_Cnt = Master_FI.Count - 1

// Récupère la liste des dossiers scan
For Loop_Idx = 1 To Master_Cnt

This code leads to an OutOfBoundsException:

// Combien d’items dans le dossier Master_FI ?
Master_Cnt = Master_FI.Count

// Récupère la liste des dossiers scan
For Loop_Idx = 1 To Master_Cnt

The following lines add “valid” folders to a DesktopListBox.

I followed my result in the DesktopListBox and discovers a folder was not reported (I read 118 lines in the DesktopListBox).

Before answering, look at the loop indice start value: 1 in both cases.
There are 119 items in the scanned folder, some are excluded (invisibles and ending with " - Data" a Folder named “Graphics” is excluded too).
The case of the Icon + CR is excluded, I placed all my target items in a brand new folder (and so without custom icon).

I am out of ideas (except blaming Tahoe…)

Mac Tahoe 26.1 / Xojo 2025r3.

Yup, because it’s an index. You should be doing 0 to count-1.

1 Like

If it’s an array it would run from 0 to count - 1. For example if count is 10 it would run from 0 to 9, which is 10 items. Accessing element 10 would result in an out of bounds error as you’ve seen.

It would be faster if you did this anyway

For each file as folderitem in Master_FI.children

1 Like

I do not used an array…

But most methods in Xojo API2 are 0 based also.

You are correct:
For Loop_Idx = 0 To Master_Cnt - 1

Works.

So FolderItem(0) = an item from the folder (a difference with API1 where I never used index 0 - it was probably returning the reference of .Parent folder: not what I wanted).

This hurt my eye, but if this is faster, I will try it after a drink.

In my test I even get:


my data folder was a child (folder) of Downloads
Xojo Applications is the folder where Xojo creates the Debug applications instead of beside the project file).

Thank you for your answers.