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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Mathcad 15 VB 6.0 automation error.

RamkrishnaShira
1-Newbie

Mathcad 15 VB 6.0 automation error.

Hi,

I am using Mathcad 13 - VB 6.0 OLE automation for calculations.

Everything was working fine till now. We are planning an upgrade to MathCAD 15.

When I tested the same VB application on MathCAD 15 version am receiving the following error. See the attached screenshot.

System Config: Windows server 2008 standard 64 bit, VB 6.0, Microsoft Office 2010.

Please let me know how can I resolve this issue.

Thanks,

Ram

ACCEPTED SOLUTION

Accepted Solutions

MC15AutomationAPI.PNG

Private Sub cmdCalc_Click()

Dim Var1 As New Mathcad.NumericValue

Dim MathcadApplication As Mathcad.IMathcadApplication2

Set MathcadApplication = New Mathcad.Application

MathcadApplication.Visible = False

MathcadApplication.Worksheets.Open "d:\TestMathcad15.xmcd"

Var1.Real = CInt(txtval.Text)

MathcadApplication.ActiveWorksheet.SetValue "A", Var1.Real

MathcadApplication.ActiveWorksheet.Recalculate

Var1 = MathcadApplication.ActiveWorksheet.GetValue("B")

txtOut.Text = Var1.AsString

Set Var1 = Nothing

MathcadApplication.ActiveWorksheet.Close mcDiscardChanges

MathcadApplication.Quit

End Sub

View solution in original post

11 REPLIES 11

This is the same computer that you yested it on with MC13, and with MC13 it worked?

Yes. It gave perfect results with MC13. I have tested it on the server.

But, When tested the same application on MC15. It is giving the error mentioned in the earlier message.

What do u think may be causing it?

I don't know. Do you really have an object called "~", with a method called "~"?

I do not have any object call "~".

Should I upload a sample code? which could be helpful?

Thanks,

Ram

Hi,

Attached is the .zip file containg sample code, Compiled .exe and the .xmcd file.

Please run the application and let me know.

When I compile and run the app from VB 6.0 IDE am getting the following error.

See the attached screenshot.

Thanks,

Ram

MC15AutomationAPI.PNG

Private Sub cmdCalc_Click()

Dim Var1 As New Mathcad.NumericValue

Dim MathcadApplication As Mathcad.IMathcadApplication2

Set MathcadApplication = New Mathcad.Application

MathcadApplication.Visible = False

MathcadApplication.Worksheets.Open "d:\TestMathcad15.xmcd"

Var1.Real = CInt(txtval.Text)

MathcadApplication.ActiveWorksheet.SetValue "A", Var1.Real

MathcadApplication.ActiveWorksheet.Recalculate

Var1 = MathcadApplication.ActiveWorksheet.GetValue("B")

txtOut.Text = Var1.AsString

Set Var1 = Nothing

MathcadApplication.ActiveWorksheet.Close mcDiscardChanges

MathcadApplication.Quit

End Sub

Hello Viacheslav,

Thanks for the code .

That helped alot. I have one more question. Is it possible to extract the graphs from the Mathcad sheet using a VB code?

I have already opened a discussion on the same 2 years ago.

http://communities.ptc.com/message/155693#155693

Thanks,

Ram

That code is for the automation API, whereas yours was for the embedding API. Which one do you need?

No, you canot extract the graphs vis the automation interface. You could embed a worksheet, but that takes us back to the embedding API. Or you could use a separate charting tool, For example ChartDirector: http://www.advsofteng.com/

He can, Richard. It's enough to run the method SaveAs():


MathcadApplication.ActiveWorksheet.SetValue "Var1", Var1.Real

MathcadApplication.ActiveWorksheet.Recalculate

Var1 = MathcadApplication.ActiveWorksheet.GetValue("Var2")

txtOut.Text = Var1.AsString

Set Var1 = Nothing

MathcadApplication.ActiveWorksheet.SaveAs "d:\TestMathcad15.html", mcHtml

MathcadApplication.ActiveWorksheet.Close mcDiscardChanges

MathcadApplication.Quit

He will get all the regions in the form of pictures. Next, you need only select the ones you want. Try it.

That's true. Good idea

Hi Richard & Viacheslav,

Thanks for the help guys.

Regards,

Ram

Announcements

Top Tags