Do BASIC ARRAYs have limitations besides memory?

I have the following code:

REM ***** BASIC *****
Option Explicit

Sub Main
CreateArraySheet2
End Sub

Sub CreateArraySheet2
Dim Sheet as Object
Dim Cell as Object
Dim NumberOfDataPoints as Integer
Dim c as Integer
Dim d as Integer

Sheet = ThisComponent.Sheets.getByName("Sheet2")
Cell = Sheet.getCellByPosition(16,4)
NumberOfDataPoints = Cell.Value
	
Dim Array(1 to 3, 1 to NumberOfDataPoints) as Single
	For c = 1 to 3
		Cell = Sheet.getCellByPosition(c,4)
		For d = 1 to Cell.Value
			Cell = Sheet.getCellByPosition(c,d+6)
			Array(c,d) = Cell.Value
		Next d	
	Next c

End Sub

When Cell = Sheet.getCellByPosition(16,4) gets above 7000 the array will start filling the array in reverse order with the value in Array(1,1). the higher the Cell value goes the the more the array fills up with the first value. What is going on?

I changed the Macro to:

Sub CreateArraySheet2
Dim Sheet as Object
Dim Cell as Object
Dim NumberOfDataPoints as Integer
Dim Data as Object
Dim c as Integer
Dim d as Integer

Sheet = ThisComponent.Sheets.getByName("Sheet2")
Cell = Sheet.getCellByPosition(16,4)
NumberOfDataPoints = Cell.Value
	
Dim Array(1 to 3, 1 to NumberOfDataPoints) as Single
	For c = 1 to 3
		Cell = Sheet.getCellByPosition(c,4)
		For d = 1 to Cell.Value
			**Data = Sheet.getCellByPosition(c,d+6)**
			**Array(c,d) = Data.Value**
		Next d	
	Next c

End Sub

Still has the same behavior. :frowning: This seems to be tied to the size of the Array. I did an Array(1 to 3, 1 to 100) with the first macro and It worked fine.

The behavior seems to start when Cell = Sheet.getCellByPosition(16,4) is equal to 5458.

It appears you’re stepping on some code. Line For d = 1 to Cell.Value has just gotten its’ value from C,4 for the loop. However, in the next statement Cell = Sheet.getCellByPosition(c,d+6) the value of Cell.Value is changed. Appears that line and the next should be a different variable.

ArrayTest.png

I made the changes above…still has the same behavior.

Using LO v5.1.1.3 I just finished a test using your code. NumberOfDataPoints Cell was set to 7300. Column(s) 1, 2, & 3 were set to values of 8, 9, & 7 respectively for 8000 rows. except that Array(1,1) would result in a value of 2. Each c, 4 value was set to 7300 also. Result showed only Array(1,1) was a value of 2. All other throughout (randomly checked of course - start, end, middle) contained the correct value. Which LO version are you running? BTW, also tried other table sizes-OK.

Just re-ran using v4.4.7.2 with same results. I also changed up the column values mixed with whole & decimal numbers and varied c,4 values. Column formats were varied as number general and with decimals. All reflected correct results.

I am running LO v5.1.2 on Windows 7. I also tried a Windows 8 machine and got the same results.

Here is where it gets strange…

I have been watching the Array values in the IDE watch window. On a hunch I threw a message box in the macro to display the the array value. Cell = Sheet.getCellByPosition(16,4) was set to 5458. When the macro was run, the watch window showed the Array(1,1) value in Array(3,5458). However, the Msgbox showed the Array(3,5458) value was 0.

Just tried on a Windows XP machine and got the same results.

Just did some testing. It looks like the IDE watch window is not displaying the actual value stored in the array cell. The Msgbox will display the value that was to be written to that cell.

In your run what was the value of cell 3,4? If less than 5458 I could understand why MsgBox reported 0 - nothing was moved into that location. IDE is confusing though. My result (using Linux xubuntu) in IDE is same as MsgBox. Both producing correct results. See attachment on my answer.