[Solved] Initialize array with ARRAY function

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
luofeiyu
Posts: 53
Joined: Thu Sep 14, 2017 2:11 am

[Solved] Initialize array with ARRAY function

Post by luofeiyu »

To call worksheet function "index" in startbasic:

Code: Select all

sub callindex()
    dim oFunAccess as object
    oFunAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
    dim oDoc, oSheet, oRange as object
    
    oDoc = ThisComponent
    oSheet = oDoc.sheets.getByName("Sheet1")
    oRange = oSheet.getCellRangeByName("a1:a47")	

    num = oFunAccess.CallFunction( "index",array(oRange,3))
    print num   
end sub
It works fine,i want to create a variable with the value "array(oRange,3)":

Code: Select all

sub callindex()
    dim oFunAccess as object
    oFunAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
    dim oDoc, oSheet, oRange as object
    
    oDoc = ThisComponent
    oSheet = oDoc.sheets.getByName("Sheet1")
    oRange = oSheet.getCellRangeByName("a1:a47")	
    
    dim oPar(1) as object
    oPar(0) = oRange
    oPar(1) = 3
    
    num = oFunAccess.CallFunction( "index",oPar)
    print num
end sub
It can't work.
https://i.sstatic.net/BSmBbGzu.png
How can fix it?

Image
Last edited by luofeiyu on Thu Jan 30, 2025 2:32 pm, edited 1 time in total.
LibreOffice 7.4.7.2 on Debian 12
User avatar
karolus
Volunteer
Posts: 1226
Joined: Sat Jul 02, 2011 9:47 am

Re: How to set the array ?

Post by karolus »

Hallo

Code: Select all

…
oPar = array( oRange, 3)
…
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
luofeiyu
Posts: 53
Joined: Thu Sep 14, 2017 2:11 am

Re: How to set the array ?

Post by luofeiyu »

Why can't define "array( oRange, 3)" with the below codes:

Code: Select all

    dim oPar(1) as object
    oPar(0) = oRange
    oPar(1) = 3
How can define it then?
LibreOffice 7.4.7.2 on Debian 12
User avatar
karolus
Volunteer
Posts: 1226
Joined: Sat Jul 02, 2011 9:47 am

Re: How to set the array ?

Post by karolus »

luofeiyu wrote: Thu Jan 30, 2025 2:12 pm
How can define it then?
:roll: see my last post above yours :roll:
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
Zizi64
Volunteer
Posts: 11477
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How to set the array ?

Post by Zizi64 »

Code: Select all

dim oPar(1) as object
    oPar(0) = oRange
    oPar(1) = 3
The 3 is not an object.


Try this:

Code: Select all

dim oPar(1) as variant
I not tried yet...
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Locked