' Example of J Server to Excel Client
'
' The demo requests random numbers from J and displays
' the numbers and their column totals. There are 2 versions
' using the EXE server and the DLL server. You can run
' these demos either from the Tools/Macro options, or
' by pressing an equivalent hotkey.

' jsdemo uses the JEXEServer
' jddemo uses the JDLLServer
'
' Switch to Sheet1, select Tools/Macro, highlight macro jsdemo
' and click Run.
'
' To get an idea of the speed of the interface, use hot-keys
' Ctrl-Shift J & K to run the two demos.

Private js As JEXEServer
Private jd As JDLLServer
Private jsflag As Boolean
Private jdflag As Boolean

Sub setjs()
' create js object if necessary
If jsflag Then Exit Sub
Set js = CreateObject("jexeserver")
jsflag = True
End Sub

Sub setjd()
' create jd object if necessary
If jdflag Then Exit Sub
Set jd = CreateObject("jdllserver")
jdflag = True
End Sub

Sub jsdemo()
setjs
Dim R As Object
Set R = Worksheets("sheet1").Range("a1:f4")
Set RSum = Worksheets("sheet1").Range("a6:f6")
ec = js.do("b=.+/a=.?4 6 $100")
ec = js.get("a", x)
ec = js.get("b", y)
R.Value = x
RSum.Value = y
End Sub

Sub jddemo()
setjd
Dim R As Object
Set R = Worksheets("sheet1").Range("a1:f4")
Set RSum = Worksheets("sheet1").Range("a6:f6")
ec = jd.do("b=.+/a=.?4 6 $100")
ec = jd.get("a", x)
ec = jd.get("b", y)
R.Value = x
RSum.Value = y
End Sub
