| View previous topic :: View next topic |
| Author |
Message |
ekleinod General User

Joined: 04 Jan 2012 Posts: 6
|
Posted: Thu Feb 02, 2012 7:20 am Post subject: Function call by name |
|
|
Hi,
I want to call an (basic) function by it's name, not directly. If figured out, I could use "executeDispatch" for this purpose, but I am not able to pass parameters to the function.
If this was solved previously, I would be delighted for a link to the solution, I did not find a similar thread.
I tried as follows:
| Code: | Sub testRPC
Dim oTestDH As Variant
Dim sTestURL As String
Dim oNoArgs() As new com.sun.star.beans.PropertyValue
Dim oParams(0) As new com.sun.star.beans.PropertyValue
MsgBox("True (direct): " & testMe(True))
MsgBox("False (direct): " & testMe(False))
oTestDH = createUnoService("com.sun.star.frame.DispatchHelper")
sTestURL = "macro:///Standard.Module1.testMe"
oParams(0).Name = "bFlag"
oParams(0).Value = True
' Variant 1
MsgBox("True (dispatch): " & oTestDH.executeDispatch(StarDesktop, sTestURL, "", 0, oParams()))
' Variant 2
MsgBox("True (dispatch): " & oTestDH.executeDispatch(StarDesktop, sTestURL & "(True)", "", 0, oNoArgs()))
oParams(0).Value = False
MsgBox("False (dispatch): " & oTestDH.executeDispatch(StarDesktop, sTestURL, "", 0, oParams()))
End Sub
Function testMe(bFlag As Boolean) As String
If (isMissing(bFlag)) Then
testMe = "no parameter"
Else
If (bFlag) Then
testMe = "trueee"
Else
testMe = "faaaalse"
End If
End If
End Function |
The direct function calls work, the dispatched calls do not. They call the function correctly but the parameter causes an error:
Variant 1 returns that the argument is not optional.
Variant 2 returns wrong value for property (I think, roughly translated from German)
Maybe there is a better solution without dispatches? Or maybe dispatches work and I do not use them correctly?
Thanks for suggestions,
Ekkart. |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Sat Feb 04, 2012 11:53 am Post subject: |
|
|
The URL to call a Basic macro is like:
vnd.sun.star.script:Library.Module.Subroutine?language=Basic&location=document (or &location=application)
At least this is what works with a hyperlink in some document. _________________ Rest in peace, oooforum.org
Get help on http://forum.openoffice.org |
|
| Back to top |
|
 |
ekleinod General User

Joined: 04 Jan 2012 Posts: 6
|
Posted: Tue Feb 07, 2012 3:09 am Post subject: |
|
|
@hanya This would be the call as in Variant 2, it does not work in my example.
@Villeroy How do I set parameters in this case?
Thanks,
Ekkart. |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Tue Feb 07, 2012 9:23 am Post subject: |
|
|
| ekleinod wrote: | @hanya This would be the call as in Variant 2, it does not work in my example.
@Villeroy How do I set parameters in this case?
Thanks,
Ekkart. |
Add your own arguments to the URL. The called Basic macro gets the full URL as argument.
Example with a simple URL parser: http://user.services.openoffice.org/en/forum/download/file.php?id=152 _________________ Rest in peace, oooforum.org
Get help on http://forum.openoffice.org |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|