Page 1 of 1

[Solved] Can't get data from sheet as array

PostPosted: Wed Nov 23, 2016 4:46 pm
by Mons1990
Hi, I'm moving my first steps with OpenOffice Basic, I found the way to do all what I need except one thing that still no works.
I have a single column with two values and I want to pass them to the macro as an array.

Code: Select all   Expand viewCollapse view
Option Explicit

Sub prova()
    Dim FoglioAttivo As Object
    FoglioAttivo = ThisComponent.getCurrentController.getActiveSheet
    Dim dimc(1, 0) As Integer
    dimc = FoglioAttivo.getCellRangebyName("A1:A2").getDataArray()
    print dimc(0, 0)
End Sub


shows me error "Variable Object not set" on the "print" line.

Where's my fault? I tried in the same way the setDataArray instruction in another part of the program and it works.

Thank you in advance

Re: Can't get data from sheet as array

PostPosted: Wed Nov 23, 2016 7:26 pm
by Villeroy
Mons1990 wrote:Where's my fault?

You do not debug.
You do not read documentation.
You do not read other peoples code.

Re: Can't get data from sheet as array

PostPosted: Wed Nov 23, 2016 7:40 pm
by Mons1990
Villeroy wrote:You do not debug.
True, I tried to install the MRI extension but it shows me an error.
Villeroy wrote:You do not read documentation.
False, I read it but i can't undestand the error.
Villeroy wrote:You do not read other peoples code.
Yes&No. I searched it on Google but i found few examples using the getDataArray() function, and the other error reported were in codes very more difficult then this.

Re: Can't get data from sheet as array

PostPosted: Wed Nov 23, 2016 8:02 pm
by Villeroy
Mons1990 wrote:
Villeroy wrote:You do not debug.
True, I tried to install the MRI extension but it shows me an error.

Set a stop mark and inspect your dimc variable.
Select an arbitrary cell range with data, call menu:Tools>Extensions>MRI>MRI <-- selection and then double-click the line starting with DataArray.
Villeroy wrote:You do not read documentation.
False, I read it but i can't undestand the error.

THIS is the documentation: http://www.openoffice.org/api/docs/comm ... eData.html
You may understand better if you would inspect your variables.
Villeroy wrote:You do not read other peoples code.
Yes&No. I searched it on Google but i found few examples using the getDataArray() function, and the other error reported were in codes very more difficult then this.

[UNO, Calc] How to fill spreadsheets cells programmatically

Anyway, this is not VBA. It is for knowlegable programmers only. You can not start a programming career with OpenOffice macros because this is too far beyond beginners level.

Re: Can't get data from sheet as array

PostPosted: Wed Nov 23, 2016 8:53 pm
by einstein
Try with:
Code: Select all   Expand viewCollapse view
Sub prova()
    Dim FoglioAttivo As Object
    FoglioAttivo = ThisComponent.getCurrentController.getActiveSheet
    dimc = FoglioAttivo.getCellRangebyName("A1:A2").getDataArray()
    For i = 0 To 1
    print dimc(i)(0)
    Next
End Sub

I have removed "Option Explicit"

Re: Can't get data from sheet as array

PostPosted: Thu Nov 24, 2016 12:54 pm
by Mons1990
Villeroy wrote:Set a stop mark and inspect your dimc variable.
Villeroy wrote:You may understand better if you would inspect your variables.
einstein wrote:Try with
Well, thank you. I found the mistake. The code does not return a multi-dimensional array but an Object that contains an array for every column it read. So I have to use it in the form varname(col)(row).

Villeroy wrote:Anyway, this is not VBA. It is for knowlegable programmers only. You can not start a programming career with OpenOffice macros because this is too far beyond beginners level.
I'm graduating now, I'd like to learn Python immediately later. I was asking because I had to edit some documents with simple macros that i wrote in VBA at University (they have MS Excel), but I have only Linux at home; and I preferred to use OpenOffice Basic and ods instead of GNU Octave and csv.

Thank you.

Re: [Solved] Can't get data from sheet as array

PostPosted: Mon Feb 01, 2021 11:27 pm
by NzKb13
Thank You, It was fine for me. I must say not always easy to find but it's some where on the WWW.