cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Mathcad Variable with Subscripts + Excel VBA Problem

ptc-4648170
1-Visitor

Mathcad Variable with Subscripts + Excel VBA Problem

Hi,

I have a very simple VBA script running in excel, which pulls values from Mathcad 14. I've run into a problem when the variable name has a subscript. VBA returns an error saying it can't find the variable.

I have tried "Test.2" for Test subscript 2, and the VBA function Chr$() to pass the Unicode of a subscript. Neither has worked for me.

Anyone have any suggestions? Does anyone know how to pull ALL of the variables names from Mathcad with VBA? That might help too.

Thanks,

Patrick

Sub Simpletest()

Dim a, b 'test varibles
Dim TestNumber

Dim oMCapp As Object
Dim oMWorkSheet As Object

Set oMCapp = GetObject(, "Mathcad.Application")
Set oMWorkSheet = oMCapp.activeworksheet

TestNumber = oMWorkSheet.getvalue("TestNumber"))


End Sub

ACCEPTED SOLUTION

Accepted Solutions
RichardJ
19-Tanzanite
(To:ptc-4648170)

I don't think there is any way to get individual elements of a vector or matrix. You have to get the entire vector or matrix as an object, then extract the element you want using GetElement. See this thread for a VBA example: http://communities.ptc.com/message/187336#187336

View solution in original post

4 REPLIES 4
RichardJ
19-Tanzanite
(To:ptc-4648170)

I have tried "Test.2" for Test subscript 2,

Is this a literal subscript or a vector subscript?

Anyone have any suggestions? Does anyone know how to pull ALL of the variables names from Mathcad with VBA? That might help too.

I don't think there is any way to do that.

Richard,

While I think I have both in my mathcad, the one I really want is a vector subscript (I think). I can almost get to it by using the region object, which has "Mathinterface" >> "XML", and I get the following (see below), for the subscribe 1 value. As you can see, I can read the value from the XML. But to do it this way I would have to run through every region, and parse the XML, which is kind of a pain.

I havn't figured out how to pull this up by the name "MS" yet. "getvalue" doesn't work. And I can't get the GetElement method to work, because I don't know how to access the correct object.

<ml:eval placeholderMultiplicationStyle="default" xmlns:ml="http://schemas.mathsoft.com/math30">

<ml:apply>

<ml:indexer/>

<ml:id xml:space="preserve">MS</ml:id>

<ml:real>1</ml:real>

</ml:apply>

<result xmlns="http://schemas.mathsoft.com/math30">

<ml:real>54.028224207857953</ml:real>

</result>

</ml:eval>
RichardJ
19-Tanzanite
(To:ptc-4648170)

I don't think there is any way to get individual elements of a vector or matrix. You have to get the entire vector or matrix as an object, then extract the element you want using GetElement. See this thread for a VBA example: http://communities.ptc.com/message/187336#187336

Thanks,

What I was missing is that you can use "Getvalue" method to return a Matrix as an object. I thought, incorrectly, that getvalue only was used for values. For example:

Dim oVector as Object
Set oVector = oMWorkSheet.getvalue("MS")

a = oVector.GetElement(0, 0)

Where oMWorkSheet is the mathcad worksheet object, and MS is the name of the variable.

Also this method seems to work on literal subscripts too.

Anyway, thanks for the help.

Announcements

Top Tags