Can an OOBasic Function return a Function??

Java, C++, C#, Delphi, ??? - Using the UNO bridges

Can an OOBasic Function return a Function??

Postby saleem145 » Mon Jan 28, 2013 5:00 pm

I want to write a function like

Code: Select all   Expand viewCollapse view
Function Foo()

         Foo="=Text(10)"

End Function


But it doesn't work....it displays it as a string....

Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
saleem145
 
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: Can an OOBasic Function return a Function??

Postby karolus » Mon Jan 28, 2013 5:04 pm

Hallo
saleem145 wrote:I want to write a function like

Code: Select all   Expand viewCollapse view
Function Foo()

         Foo="=Text(10)"

End Function


But it doesn't work....it displays it as a string....

Saleem


What do you expect ? - it is a string
AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 852
Joined: Sat Jul 02, 2011 9:47 am

Re: Can an OOBasic Function return a Function??

Postby saleem145 » Mon Jan 28, 2013 5:21 pm

To output 10 instead of =Text(10)

Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
saleem145
 
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: Can an OOBasic Function return a Function??

Postby karolus » Mon Jan 28, 2013 5:27 pm

saleem145 wrote:To output 10 instead of =Text(10)

Saleem

Code: Select all   Expand viewCollapse view
Function Foo()

         Foo= str(10)

End Function
AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 852
Joined: Sat Jul 02, 2011 9:47 am

Re: Can an OOBasic Function return a Function??

Postby Charlie Young » Mon Jan 28, 2013 5:39 pm

If you want to format the text, you can use the Format function.

Code: Select all   Expand viewCollapse view
Function FormattedFoo() As String
   FormattedFoo = Format(10,"##.0")
End Function


Obviously the 10 and the format can be arguments to the function. But of course since Format() and Str() are both functions themselves, there is no point in wrapping them in functions by their lonesome.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Can an OOBasic Function return a Function??

Postby rudolfo » Tue Jan 29, 2013 2:51 am

saleem145 wrote:I want to write a function like

Code: Select all   Expand viewCollapse view
Function Foo()
         Foo="=Text(10)"
End Function


But it doesn't work....it displays it as a string....

Saleem


I guess you think the function returns: =Text(10).
Which would in deed be evaluated to 10 if you type this in the input field for a cell. But that's trap. What it really returns is: '=Text(10).
In other words, the leading equal sign that usually introduces a formula is escaped with the quote and this prevents the part after the equal sign to be evaluated as a formula.
Or in short there is no such thing as recursive evaluation in this case. Typically you will write =Foo() in cell A3 and it will evaluate to =Text(10), but this result is not interpreted as a formula again.

This is in long words what Karolus pointed out very significantly: What do you expect ? - it is a string
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
rudolfo
Volunteer
 
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Can an OOBasic Function return a Function??

Postby JPL » Tue Jan 29, 2013 4:51 pm

Hello,

If you are looking for the dynamic execution of some Basic code then you need the equivalent of the
Code: Select all   Expand viewCollapse view
Eval("...")

VBA function, which is not available in Basic.

If you are looking for the execution in Basic of Calc functions, then have a look at the XFunctionAccess interface (http://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/XFunctionAccess.html).
As an example:

Code: Select all   Expand viewCollapse view
Dim oFunctionAccess As Object, vResult As Variant
   Set oFunctionAccess = createUnoService("com.sun.star.sheet.FunctionAccess")
   vResult = oFunctionAccess.callFunction("TEXT",Array(10, "0,00"))
   MsgBox vResult

Hoping this will help.
JPL

PS: note that for above example the standard Format Basic function will do the job as well ...
KUbuntu 18.04 / LibO 6.4
Access2Base (LibO).
BaseDocumenter extension (LibO)
Documentation on http://www.access2base.com and http://www.access2base.com/basedocumenter
JPL
Volunteer
 
Posts: 107
Joined: Fri Mar 30, 2012 3:14 pm

Re: Can an OOBasic Function return a Function??

Postby saleem145 » Mon Feb 04, 2013 10:01 pm

Yeah, I was looking for dynamic execution of some function...its even more complicated...I would like to return a 2 dimensional dataset and only some columns would contain a function other regular data....

Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
saleem145
 
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: Can an OOBasic Function return a Function??

Postby saleem145 » Mon Feb 04, 2013 10:01 pm

Yeah, I was looking for dynamic execution of some function...its even more complicated...I would like to return a 2 dimensional dataset and only some columns would contain a function other regular data....actually some columns would contain a hyperlink which when clicked would call a macro and others regular data....

if I can return a hyperlink instead of function that would solve my problem too....

Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
saleem145
 
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: Can an OOBasic Function return a Function??

Postby Jan_J » Tue Feb 05, 2013 10:57 am

If you had access to the range you are working on, you should be allowed to set Formula properties of cells within the range. But this approach requires using a subroutine, not a function in Basic.
JJ ∙ http://forum.openoffice.org/pl/
LO (6.1|6.0) ∙ AOO 4.1.5 ∙ Python (3.7|2.7) ∙ Unicode 11 ∙ LᴬTeX 2ε ∙ XML ∙ Unix tools ∙ Linux (2.6|3.x) ∙ Fedora ∙ CentOS ∙ SUSE
Jan_J
 
Posts: 143
Joined: Wed Apr 29, 2009 1:42 pm
Location: Poland

Re: Can an OOBasic Function return a Function??

Postby karolus » Tue Feb 05, 2013 12:40 pm

Hallo
@Jan
Its not a Question of Function or Sub, its a Questions of 'where from the Function is called?' - from Spreadsheet as UDF or not.

Karolus
AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 852
Joined: Sat Jul 02, 2011 9:47 am

Re: Can an OOBasic Function return a Function??

Postby Jan_J » Tue Feb 05, 2013 4:15 pm

OK, karolus, You're right. I was responding by heart. When you make call from the code, both subprogram forms -- subroutines and functions as well -- have access to API objects.
But even so, if one has infomation about a cell or a range, he/she can set a formula in this cell during function call -- not by result, but by a side effect. I believe this may help to solve the problem.
JJ ∙ http://forum.openoffice.org/pl/
LO (6.1|6.0) ∙ AOO 4.1.5 ∙ Python (3.7|2.7) ∙ Unicode 11 ∙ LᴬTeX 2ε ∙ XML ∙ Unix tools ∙ Linux (2.6|3.x) ∙ Fedora ∙ CentOS ∙ SUSE
Jan_J
 
Posts: 143
Joined: Wed Apr 29, 2009 1:42 pm
Location: Poland


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest