Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
I use a 3D plot VBscript component inside MathCAD 15.
This component has an input variable. When I put an array of several vectors (or matrices) as input variable all is OK (VB gets it as Variant
and I can loop over its elements).
But when the input variable is an array of only one vector (or matrix) VB gets it as Double
and the value of this double is -1.#QNAN
. So I can't use input variable for the next calculations.
Please see attached file for reference.
I got the same results as you and think this must be a bug.
I played around with it for a little while, and came up with a possible work-around:
You can force the input to be at least two elements by stacking it with another value.
Example: stack(OneElementVector,0)
Then, revise your VBscript loop to "For i=0 to UBound(M)-1"
Certainly not very elegant, but at least it works.
Hi Igor
Following code gets M as an array of variants, but I can't extract the correct values, if case that they are there and it is not just an array of NaN's.
Best regards.
Alvaro.
Sub ScriptObjEvent_Exec(Inputs,Outputs)
'// generate plot data
Dim M,MM
Dim x, y, z
M = Inputs(0).Value(0) ' this M is an array of variants
RemoveSurfaces
If IsArray(M) Then
For i=0 to UBound(M)
MM=M(i) ' MM is an array of variants, can check with a msgbox
x = MM ' MM(0) gives error
y = MM
z = MM
a = AddScatterPlot(x,y,z) ' just plots an isolated point.
Next
End If
Outputs(0).Value(0)=Rotation
Outputs(0).Value(1)=Tilt
Outputs(0).Value(2)=Twist
End Sub
I agree with Mark. It's a bug, and what the vbscript receives is not usable.
With the code above, VarType for M is 8204, an array of single precision floating point numbers. VarType for M2 is also 8204, but the array has a LBound and a UBound of 0, and if I try to look at M2(0) I get a subscript out of range error.
I've found very simple solution for my situation:
If IsArray(inputVar)=False Then inputVar=Array(inputVar)