Hello Monks, I was hoping that one of you may be able to help me with a problem that I can not figure out. I have VBA code for mathcad interaction as follows:
Dim mathcad, worksheets, sheet Set mathcad = CreateObject("Mathcad.Application") set worksheets = mathcad.Worksheets Set sheet = worksheets.Open("C:\vbscript\testM12.xmcd") sheet.setValue "x",50 sheet.setValue "y",60 sheet.setValue "z",70 sheet.Recalculate MsgBox(sheet.getValue("output1")) MsgBox(sheet.getValue("output2"))
I took this code and used the Win32::OLE module and tranlateded the code into perl and got:
#!/usr/ym/util/perl use Win32::OLE; #Perl "C:/documents and settings/aaron.verellen/desktop/trial2.pl" Win32::OLE->Option(Warn => 2); #use existing instance if mathcad is already running eval {$MC = Win32::OLE->GetActiveObject('Mathcad.Application')}; die "Mathcad not installed" if $@; unless (defined $MC) { $MC = Win32::OLE->new('Mathcad.Application', sub{$_[0]->Quit;}) or die "Unable to start Mathcad"; } #Open specific worksheet my $filePath = 'C:\Documents and Settings\aaron.verellen\Desktop\testM +12.xmcd'; my $WS = $MC->Worksheets; my $S = $WS->Open($filePath); #Set values on the worksheet $S->setValue('x',50); $S->setValue('y',60); $S->setValue('z',70); $S->Recalculate; my $answer1 = $S->getValue('output1'); my $answer2 = $S->getValue('output2'); print "($answer1,$answer2)\n";
Looking at what the mathcad program does, the code does exactly what it is suppose to with one exception...I can not get output1 and output2 back. The getValue does not seem to work. When I run the script I get:

C:\>Perl "C:/documents and settings/aaron.verellen/desktop/trial2.pl"
Win32::OLE(0.1709) error 0xc00000fd
in METHOD/PROPERTYGET "getValue" at C:/documents and settings/aaron.verellen /desktop/trial2.pl line 30

I have tried the Invoke command and get the same error. Does anyone know why this particular methode does not work or have suggestions I could try to get it to work?

Thank you so much,
Aaron


In reply to WIN32::OLE bridging to MATHCAD by forgedascendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.