cancel
Showing results for 
Search instead for 
Did you mean: 
Security Alert Log4j Security Vulnerability. Click here to know more.
cancel
Showing results for 
Search instead for 
Did you mean: 

VBscript problem with one element vector

ifomenko
15-Moonstone

VBscript problem with one element vector

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.


4 REPLIES 4
MJG
18-Opal
18-Opal
(To:ifomenko)

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

RichardJ
19-Tanzanite
(To:ifomenko)

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.

ifomenko
15-Moonstone
(To:ifomenko)

I've found very simple solution for my situation:

If IsArray(inputVar)=False Then inputVar=Array(inputVar)

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."