Odd NilObjectException

I agree with @Tim_Parnell and Norman. An array is a collection, so I’d expect an empty box rather than a box that doesn’t exist. An array with no members makes more sense than Nil to me. There is, however, precedent for both elsewhere in the programming world with what seems to be a heavier leaning toward allow Nil (null, undefined) array references being possible.

Regardless, I suspect this change is just too far-reaching. I know that I never expect an array reference to be Nil even though I have run in to it in the past, but who knows how much code is out there that does rely on checking the validity of the reference? I don’t expect this to be changed.

The difference is as MyClass, that’s returning a single instance.

If you were to define the return type as MyClass(), an array of MyClass objects, why would that be a single nil instance?

Why would that even be able to be stored in an array variable? At worst I would expect a TypeMismatchException, but would prefer the convenience of an empty array. I mean, convince is the whole point of using a framework.

Today I learned arrays much more duct-tape and bubble gum than I had previously expected.

Because the function returns a single array.

But surely:

ReDim MyArray(-1)

Sets an array that exists to have no elements, not destroys the array completely. Otherwise you would’t be able to do:

ReDim MyArray(-1)
MyArray.Add "Some data"

As far as I am aware you can’t set an array to nil.

Sure, you can:

dim s(-1) as String
s = Nil

Which is fine, I just wasn’t aware of it :slight_smile:

ReDim shouldn’t be setting it to Nil though, otherwise:

ReDim MyArray(-1)
MyArray.Add "Some data"

Would throw a NilObjectException.

Redim is not setting it to Nil, it was already Nil, then Redim throws the NilObjectException

Dim MyArray() As String
MyArray = Nil
Redim MyArray(-1)

Ah… I see. Fair enough.