Folderitem.constructor from listbox

[code] for i = 0 to FilesListbox.ListCount step 1

    Dim openfile As FolderItem
    openfile.constructor(FilesListBox.cell(i,0),openfile.PathTypeAbsolute) // <----- This line is producing a NilObjectException bug... WHAT DID I DO?!
    if openFile <> nil and openfile.Exists then

What have I done wrong here.

Thank you so much

Listbox rows are zero based. The listbox.Listcount is not. Your cell(i, 0) is going out of bounds on the last iteration

for i = 0 to FilesListbox.ListCount-1 //step 1 <- is not needed

openFile IS nil, so can’t call any method on it. What’s more, this is not the way you’d call the Constructor anyway.

dim openFile as FolderItem
openFile = new FolderItem( path, type )

or simply:

dim openFile as new FolderItem( path, type )

The “new” operator will call the appropriate constructor based on the parameters you’ve given.


This is invalid syntax for invoking the Constructor method. Constructors are (almost) never called by name but rather by using the New keyword and the name of the class.

openfile = New FolderItem(FilesListBox.cell(i,0),openfile.PathTypeAbsolute) ' invokes the Constructor method

You are receiving a NilObjectException in your original code because the object openfile is Nil. You cannot call a method (even Constructor) on a Nil object.

Now, I seem to be getting an OUTOFBOUNDSEXCEPTION error with the code:

[code] for i = 0 to FilesListbox.ListCount step 1

    dim openFile as FolderItem
    openFile = new FolderItem(FilesListBox.cell(i,0),openfile.PathTypeAbsolute) <--- OUTOFBOUNDSEXCEPTION error same line as before
    if openFile <> nil and openfile.Exists then

Now what :frowning:

Thanks you all!

for i = 0 to FilesListbox.ListCount-1


Not for nothing, but Roger posted that in the second post in this thread.

Missed it and reallocated credit for the completion. Thanks for keeping me fair!

Cool. And if you haven’t already, you’ll have plenty of opportunities to give @Michel Bujardet credit in the future. We all have. :slight_smile:

Indeed Roger gave the solution right away. That base 1 and zero things happens so often, we all have been bitten !

One of the best changes in the new framework is making everything zero-based.