Page 1 of 1

[Solved] Initialize array with ARRAY function

Posted: Thu Jan 30, 2025 11:39 am
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

Re: How to set the array ?

Posted: Thu Jan 30, 2025 1:25 pm
by karolus
Hallo

Code: Select all

…
oPar = array( oRange, 3)
…

Re: How to set the array ?

Posted: Thu Jan 30, 2025 2:12 pm
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?

Re: How to set the array ?

Posted: Thu Jan 30, 2025 2:22 pm
by karolus
luofeiyu wrote: Thu Jan 30, 2025 2:12 pm
How can define it then?
:roll: see my last post above yours :roll:

Re: How to set the array ?

Posted: Thu Jan 30, 2025 2:32 pm
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...