Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- VBscript problem with one element vector

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

10-12-2016
02:55 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-12-2016
02:55 AM

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

10-12-2016
01:36 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-12-2016
01:36 PM

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.

10-12-2016
05:52 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-12-2016
05:52 PM

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

10-12-2016
06:50 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-12-2016
06:50 PM

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.

08-12-2017
03:33 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-12-2017
03:33 PM

I've found very simple solution for my situation:

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