This is a follow-up question to Execute a Python Macro (Function) From Base and Return Value to Base. While the use of the Invoke Method works, I do not understand how this method is able to pass values from one subroutine to the other. What variables (values) needs to be passed through the method and what values the method will return. Consequently, I have not been able to successfully modify the existing code structure. What I have found on the internet has proven to be to cryptic for me. I have been unable to locate an easy to comprehend tutorial that would review how the Invoke Function works.
In the example below, “a” essentially works as expected. I can pass a value through “a” and get a return value. However, what is the purpose of “b” and “c”? If I delete them, the script fails. The implication is that these variable must be required by the method for a reason. Are they parameters of some type? Unfortunately, I have not located an understandable explanation, at least for me. Uno Basic function below:
Function dblTestPython(dblValue) As Double On Error Goto HandleError1001 dim a(0), b(0), c(0) as variant a(0)= Forms("MainForm").Controls("Field1").value scpr = ThisComponent.getScriptProvider scmod = scpr.getScript("vnd.sun.star.script:call_me.py$call_me?language=Python&location=user") returnFromPython = scmod.invoke(a,b,c) print returnFromPython Exit Function HandleError1001: resume next End Function
Below is the Python script invoked by the Basic function above:
import os def call_me(a): z = int(a) * 5 return z