VBScript only works with arrays of Variants, i.e. it does not support VT_ARRAY+VT_DOUBLE, only VT_ARRAY+VT_VARIANT. So each double needs to be "boxed", which exactly corresponds to J's boxed array. However, the array can be either nested (list of lists) or rectangular, i.e. Dim A(x,y,z...).
Get/Set and GetB/SetB are different in using byte array as opposed to BSTR for string type.
Here's a few examples, which should take care of the use cases, with results below.
Script |
Result |
''''''''''''''''''''''''''''''''''''''''''''''''''
Dim r, j: Set j = CreateObject("JDLLServer") |
Setup |
WScript.Echo "== Example 1 =="
Dim A1: A1 = Array(1.1, 1.2, 1.3)
' pass an array
r = j.Set("A1", A1)
' see that the array is boxed
WScript.Echo(" $A1" & vbCrLf & DoR("$A1"))
WScript.Echo(" A1" & vbCrLf & DoR("A1"))
' unbox the array
j.Do "A2=: >A1"
' see unboxed array
WScript.Echo(" $A2" & vbCrLf & DoR("$A2"))
WScript.Echo(" A2" & vbCrLf & DoR("A2"))
' calc result
j.Do "B2=: +/\A2"
' box
j.Do "B1=: <""0 B2"
' fetch result
Dim B2: r = j.Get("B1", B2)
' print result
WScript.Echo " Result:"
WScript.Echo Join(B2, ",") |
== Example 1 == $A1 3 A1 +---+---+---+ |1.1|1.2|1.3| +---+---+---+ $A2 3 A2 1.1 1.2 1.3 Result: 1.1,2.3,3.6 |
WScript.Echo "== Example 2 =="
A1 = Array(Array(1.1, 1.2, 1.3), _
Array(2.1, 2.2, 2.3), _
Array(3.1, 3.2, 3.3))
r = j.Set("A1", A1)
WScript.Echo(" A1" & vbCrLf & DoR("A1"))
j.Do "A2=: >&>A1"
j.Do "B2=: +/\A2"
j.Do "B1=: <""1<""0 B2"
r = j.Get("B1", B1)
WScript.Echo " Result:"
WScript.Echo Join(B1(0), ",")
WScript.Echo Join(B1(1), ",")
WScript.Echo Join(B1(2), ",") |
== Example 2 == A1 +-------------+-------------+-------------+ |+---+---+---+|+---+---+---+|+---+---+---+| ||1.1|1.2|1.3|||2.1|2.2|2.3|||3.1|3.2|3.3|| |+---+---+---+|+---+---+---+|+---+---+---+| +-------------+-------------+-------------+ Result: 1.1,1.2,1.3 3.2,3.4,3.6 6.3,6.6,6.9 |
WScript.Echo "== Example 3 =="
ReDim A1(2,2)
A1(0,0)=1.1 : A1(0,1)=1.2 : A1(0,2)=1.3
A1(1,0)=2.1 : A1(1,1)=2.2 : A1(1,2)=2.3
A1(2,0)=3.1 : A1(2,1)=3.2 : A1(2,2)=3.3
r = j.Set("A1", A1)
WScript.Echo(" A1" & vbCrLf & DoR("A1"))
j.Do "A2=: >A1"
j.Do "B2=: +/\A2"
j.Do "B1=: <""0 B2"
r = j.Get("B1", B1)
WScript.Echo " Result:"
For i = LBound(B1,1) To UBound(B1,1)
s = ""
For k = LBound(B1,2) To UBound(B1,2)
s = s & B1(i,k) & " "
Next
WScript.Echo s
Next |
== Example 3 == A1 +---+---+---+ |1.1|1.2|1.3| +---+---+---+ |2.1|2.2|2.3| +---+---+---+ |3.1|3.2|3.3| +---+---+---+ Result: 1.1 1.2 1.3 3.2 3.4 3.6 6.3 6.6 6.9 |
{{{ ' End Set j = Nothing WScript.Echo "End" Function DoR(exp)
End Function }}} |
Tear Down |
