如何从OpenOffice Basic函数返回数组? [英] How do I return an array from an OpenOffice Basic function?
问题描述
我正在阅读关于数组的OpenOffice 上的文档,看来像Calc
一样具有像Excel
一样的数组功能.
I'm reading through the documentation on OpenOffice regarding arrays and it seems like Calc
is capable of array functions just like Excel
.
为了对此进行测试,我创建了一个简单的函数,该函数应返回数组{1, 2, 3}
:
To test this I created a simple function that should return an array {1, 2, 3}
:
Function Test()
Dim Test(3) As Variant
Test(1) = 1
Test(2) = 2
Test(3) = 3
End Function
当我用=Test()
填充一个单元格并按Ctrl+Shift+Enter
时,我得到的只是一个带有3
的单元格. 1
和2
在哪里?我在做什么错了?
When I populate a cell with =Test()
and press Ctrl+Shift+Enter
I just get a cell with 3
in it. Where are 1
and 2
? What am I doing wrong?
我正在运行OpenOffice 4.1.1
.
推荐答案
函数返回类型的尺寸必须在Function
语句内完成.如果函数将返回一个数组,则它的尺寸必须为Variant
.在starbasic中,无法直接将函数标注为数组类型.数组本身可以在函数体内单独创建,然后作为返回值分配给函数.
The dimensioning of an function return type must be done within the Function
statement. If the function shall return an array, then it must be dimensioned as Variant
. There is no way in starbasic dimensioning the function as array type directly. The array itself can be created separately within the function body and then assigned to the function as return value.
像这样:
Function Test() as Variant
Dim arr_Test(1 to 3) As Integer
arr_Test(1) = 1
arr_Test(2) = 2
arr_Test(3) = 3
Test = arr_Test
End Function
或者如果您想缩短它,可以使用内置的Array
函数,该函数返回包含数组的Variant
.
Or if you want it shorter, you could use the built-in Array
function which returns a Variant
containing an array.
像这样:
Function Test2() as Variant
Test2 = Array(1,2,3)
End Function
openoffice-/libreoffice-/-BASIC编程的文档:
Documentations for openoffice- / libreoffice- / -BASIC programming:
https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide
https://wiki.openoffice.org/wiki/Documentation/DevGuide/OpenOffice.org_Developers_Guide -> https://wiki.openoffice. org/wiki/Documentation/DevGuide/Basic/OpenOffice.org_Basic
但是两者都没有完全参考BASIC基础;-),例如所有内置函数的参考.
But both have not fully references for BASIC basics ;-) such as references for all built-in functions.
https://help.libreoffice.org/Basic/Basic_Help -> https://help.libreoffice.org/Basic/Run-Time_Functions 似乎几乎完全.
https://help.libreoffice.org/Basic/Basic_Help -> https://help.libreoffice.org/Basic/Run-Time_Functions seems to be almost completely.
这篇关于如何从OpenOffice Basic函数返回数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!