Ask Your Question
0

Do BASIC ARRAYs have limitations besides memory?

asked 2016-04-14 18:34:23 +0200

lancecycles gravatar image

updated 2016-04-15 01:23:32 +0200

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. :( 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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2016-04-14 21:09:21 +0200

Ratslinger gravatar image

updated 2016-04-15 19:38:01 +0200

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

edit flag offensive delete link more

Comments

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

lancecycles gravatar imagelancecycles ( 2016-04-15 01:14:35 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2016-04-15 04:20:53 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2016-04-15 15:13:25 +0200 )edit

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.

lancecycles gravatar imagelancecycles ( 2016-04-15 17:43:36 +0200 )edit

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

lancecycles gravatar imagelancecycles ( 2016-04-15 18:58:33 +0200 )edit

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.

lancecycles gravatar imagelancecycles ( 2016-04-15 19:11:25 +0200 )edit

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.

Ratslinger gravatar imageRatslinger ( 2016-04-15 19:36:52 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-04-14 18:34:23 +0200

Seen: 121 times

Last updated: Apr 15 '16