Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Mathcad from Visual Basic

Status
Not open for further replies.

HIlg

Electrical
Dec 3, 2002
3
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

 
Replies continue below

Recommended for you

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

Cheers
Harald
 
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
 
HIlg - I am interested in the process. I'd be happy if you emailed it to davidr@fast.net. Thanks !!
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor