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
- :
- Re: Import Unit/Dimension

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

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

04-26-2011
12:49 AM

04-26-2011
12:49 AM

Import Unit/Dimension

Is it possible to import the unit/dimension of a variable from Mathcad to VBA? I understand that Mathcad stores all values in SI units, therefore, the GetValue function will always import a length dimension in units of meters. My programming, however, cycles through a list of variables (of varying dimensions) and imports their values (using GetValue) from a given Mathcad worksheet, and I would like to convert units within VBA.

The following demonstrates what I'd like to do. It would import variables of length, mass, dimensionless, or text and convert from their standard SI units to what I typically use (in, lb, dimensionless, and text):

McadValue = WS.GetValue(VariableName)

Select Case WS.GetDimension(VariableName) <--- is there something equivalent to GetDimension?

Case “Length”

Mult = 39.3701 ‘Convert meters to inches

Case “Mass”

Mult = 2.20462 ‘Convert kg to lb

Case “Dimensionless”

Mult = 1

Case Else

Mult = 0 <--- I use this for text fields, I can modify as necessary if text is handled differently.

End Select

If Mult = 0 Then

vbValue = McadValue ‘for variables which contain text

Else

vbValue = McadValue * Mult ‘for variables which contain numeric values

End If

I searched some other threads and only found discussions of trying to obtain a variable’s unit. I do not need the unit, just the dimension.

Please let me know if anything like this is possible (I realize if it exists, it’s probably not in as nice of a format as I’d like, so I’ll need to make some modifications to my example script above).

Thank you in advance.

Labels:

3 REPLIES 3

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

04-26-2011
05:10 AM

04-26-2011
05:10 AM

Re: Import Unit/Dimension

Stuart posted a worksheet a while back which might be of some use, but I'm struggling to find it. I think it was called Parsing units, or something similar.

Mike

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

04-26-2011
08:45 AM

04-26-2011
08:45 AM

Re: Import Unit/Dimension

Stuart posted a worksheet a while back which might be of some use, but I'm struggling to find it. I think it was called Parsing units, or something similar.

Found the worksheet I was talking about.

Have a look if it helps.

Mike

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

04-26-2011
07:57 AM

04-26-2011
07:57 AM

Re: Import Unit/Dimension

There was a long discussion about this recently, here:

http://communities.ptc.com/thread/34270

This is the only possibility.