stdVBA icon indicating copy to clipboard operation
stdVBA copied to clipboard

stdArray starts at 1 instead of 0

Open SZanko opened this issue 4 years ago • 3 comments

Description

In the current implementation of the stdArray it starts at 1 instead of 0, however in vba and javascript the array starts at 0 is this a planned design decision or is it designed to be that way?

Example

    Dim arr As stdArray
    Set arr = stdArray.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    Debug.Print (arr(0)) 'throws an error
    Debug.Print (arr(1))

Error

Runtime error: 9 Index out of range

Expectation

stdArray starts at 0

SZanko avatar Dec 07 '21 13:12 SZanko

It is designed to be this way, however happy to add a feature for rebasing the array to start at 0 (or any integer for that matter)

sancarn avatar Dec 07 '21 13:12 sancarn

It is fine that the array starts a 1. However it should be mentioned that it starts at 1 instead of zero I haven't read any info which says that it starts at 1. Maybe you should mention it somewhere

But it would be nicer if it use 0 as start point for the following reason that it is easier to migrate existing vba code without this lib. However that would break backwards compatibility with existing users of the lib

SZanko avatar Dec 07 '21 14:12 SZanko

However it should be mentioned that it starts at 1 instead of zero I haven't read any info which says that it starts at 1. Maybe you should mention it somewhere

Yes the documentation for stdArray is currently not written. However it is present in both the tests and the code.

But it would be nicer if it use 0 as start point for the following reason that it is easier to migrate existing vba code without this lib.

Indeed, we can make a global option on stdArray for defaultBase, similar to what we do for stdLambda 's function lookup.

sancarn avatar Dec 07 '21 14:12 sancarn