×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using Mathcad from Visual Basic

Using Mathcad from Visual Basic

Using Mathcad from Visual Basic

(OP)
Hy,
hope, this one is easy:
I have the formula of a matrix calulation in a mathcad file. Now I need to send a 9x9 matrix, which consists of measurements from an automization process, from Visual Basic to this calculation and receive the result in Visual Basic.
I 've never done anything with Mathcad and I try not to touch the equation itself for I don't understand it. How difficult is this?

Any help is appreciated!
Cheers
Harald

RE: Using Mathcad from Visual Basic

(OP)
Hy there,
unfortunately nobody seems to have an answer. Well, I got one now. If everybody's interested, send me a note!

Cheers
Harald

RE: Using Mathcad from Visual Basic

How do you use the OLE feature in mathcad to make a matrix in Excel with VBA.  I can't figure ot out.  Why would they make a math program that only sends 1-D arrays into Mathcad...last I checked Excel already does that. I am getting frustrated with mathacd and please nobody show me that easy 1-D example in the manual like mathsoft did.  

SOMEONE HELP ME.
demst37

RE: Using Mathcad from Visual Basic

HIlg - I am interested in the process.  I'd be happy if you emailed it to davidr@fast.net.  Thanks !!

RE: Using Mathcad from Visual Basic

(OP)
Hy there,
I hope, we are talking about the same problem, mine was to start Mathcad from within VB, send data to it, let it recalculate and get the answer.

First thing is to start the Mathcad app. Therefore you need to add the reference "Mathcad Automation 1.0 Type Library" to your VB project which was available right after the Mathcad installation.

Then you need to create a Mathcad object. I did this in two steps:
- create an OLE object on a form ("MathCadOLE")
- create a Mathcad object in the code:
Dim McadObj1 As MathcadOld

Then you start the Mathcad app and open your document:

'frmMain.MathCadOLE.CreateLink ("C:\Temp\TestMCAD.mcd")
frmMain.MathCadOLE.CreateEmbed ("C:\Temp\TestMCAD.mcd")
Set McadObj1 = frmMain.MathCadOLE.object

I didn't figure out the difference between CreateLink and CreateEmbed.

After that, one can use the functions GetComplex, SetComplex
and Recalculate with the McadObj1 object. Furthermore you can access the worksheet property and have thousands of functions.

Now my first try to send data to Mathcad and back was to use the function PRNLESEN and PRNSCHREIBEN (I don't know the englisch counterpart) to read and write matrices to ASCII files but unfortunately the PRNSCHREIBEN wouldn't react on the Recalculate command.
 
So I used the functions SetComplex and GetComplex.
To set an array I'd dim the array as variant:
    Dim Mr(1 To 3, 1 To 3) As Variant
    Dim Mi(1 To 3, 1 To 3) As Variant,
fill the real part array with my values and send it to Mathcad via
Call McadObj1.SetComplex("in0", Mr, Mi)
It just ignores the imaginary parts if they are all set to 0.
Then it needs to be recalculated and the result can be got by
Label1.Caption = McadObj1.GetComplex("out0", ResR, ResI).
where ResR and ResI are just non-dimensioned Variants.

Well, I hope that helps. I don't know how to submit source code to a post in this forum, but if anyone is interested just leave me a note.

Cheers
Harald

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close