(First, some nitpicks. The GlobalScope.BasicLibraries.loadLibrary("ScriptForge") is completely unnecessary in your example, and only distracts. Also, if you want a single-element array, you should use (0 to 0) - otherwise, what your unused element is intended for in the demo?)
This is a complex bug.
- If you put breakpoints, and inspect
dataRow at each line (I know that everyone doing any programming uses debugger and watch window, right?), you will see that dataRow is Integer(0 to -1) after its Dim statement; it is Variant(0 to -1) after assignment of array(); and it is Empty(0 to 1) after ReDim. The final type of elements is, as told, Empty - and that is the type that can only one possible value: Empty. You can assign any value to it; and the result is still Empty. This is what happens in your case.
- If you drop the assignment of
array(), it starts working. The difference is that it doesn’t have to change the type of elements, so it is Integer(0 to 1) after ReDim, meaning that elements store assigned numbers as expected.
- Now, with removed assignment of
array(), try to change the element type - either in Dim, or in ReDim. And this time, the code will fail compilation, with message “BASIC syntax error. Variable dataRow already defined.”. This shows, that you can not re-define the type of elements.
(Some?) problems are:
- Why is there the syntax to specify the type in
ReDim, when you can’t actually change it?
- Why isn’t this documented?
- Why is it still allowed to re-define it indirectly - using assignment of another array (e.g., created by
Array function)?
- Why is it allowed to
ReDim such an indirectly defined array with another element type, and why does it not fail, but silently assigns a different type?
While this is a topic for a bug report, the expected use is that you don’t use ReDims that change the element type of arrays.