Skip to main content
1-Visitor
August 20, 2012
Solved

Mathcad Variable with Subscripts + Excel VBA Problem

  • August 20, 2012
  • 1 reply
  • 5596 views

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

Best answer by RichardJ

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

1 reply

19-Tanzanite
August 20, 2012

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.

1-Visitor
August 20, 2012

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>
RichardJ19-TanzaniteAnswer
19-Tanzanite
August 20, 2012

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