Scala
runs on the JVM
, and VBA
does not, Therefore there is no native way to pass objects between them.
There are two alternatives to communicate between Scala
and VBA
:
One option is to start a new process for each procedure call and parse the output, as @OlivierBlanvillain suggested in his answer.
I think that the preferred method, is communicating in web sockets, and particularly http
using a web server.
Web Server
Use a scala web server (there are tons of them), for example scalatra, and each procedure call should be mapped to a http request to localhost:
Scala server code (with scalatra)
class ScalaCall extends ScalatraServlet {
get("/:func/:params") {
Calling function {params("func")} with parameters {params("params")}
}
}
VBA Client code
Public Function ScalaCall(ByVal func As String, ByVal params As String) As String
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", "http://127.0.0.1/" & func & "/" & params, False
WinHttpReq.Send
If WinHttpReq.Status = 200 Then
ScalaCall = WinHttpReq.ResponseBody
End If
End Function
Calling ScalaCall("f","x")
on VBA
should invoke a request to the scala
server, that will output Calling function f with parameters x