Skip navigation
1889 Views 8 Replies Latest reply: Dec 15, 2011 10:40 AM by MikeArmstrong RSS
Copper 6 posts since
Aug 10, 2000
Currently Being Moderated

Oct 18, 2002 12:00 AM

VB Custom Component - Observations and Questions

Been playing around with a VB6 ActiveX component as a Scriptable Object Component in MathCAD 2000 Pro to obtain processing speed advantages of compiled code for some intensive non-standard matrix calculations. Initial speed tests on simple looping indicate a speed gain factor of 1000.

Observations:
1) As noted elsewhere, user interaction with editable controls in the ActiveX component causes lots of headaches. For my purposes, the component will have non-editable display fields only.
2) If my single input is a vertical vector (many rows, one column) then in my VBScript the Inputs(0).Value is a 1-dimensional array (i.e. use one subscript only). If the input is a 2-dim matrix (many rows, many columns) or a 1-dim horizontal vector (many columns, one row), then the resulting Inputs(0).Value is a 2-dim array (i.e. use 2 subscripts).
3) As noted elsewhere, the controls in the ActiveX component do not print properly when printing the MathCAD sheet.
4) The ActiveX control does not scale properly when changing the Zoom magnification. I presume I could included resizer code in my VB component and interaction with the Ambient properties of the MathCAD environment, but this is a lot of work when I don't really want the visual interface anyway.
5) The imbedded Component seems very fussy. I keep getting many voodoo "An internal error has occurred" messages, and, of course, I have no idea what is going wrong. After getting the message, if I execute again, the Component seems to work fine without complaining.
6) The documentation and samples provided with MathCAD 2000 Pro

Questions:
1) Can anyone give me insight into why I am getting these "An internal error has occurred" messages and how to avoid them?
2) My objective is to obtain the processing speed of compiled code, not to create custom user interface controls for MathCAD. Is it feasible to write VB .DLLs instead for the same purpose, and avoid the user interface hassles? Writing C / C++ .DLLs is beyond my skill set. If so, any insight into how the vector / matrix data in MathCAD can be passed to / from functions contained in my VB .DLLs?

Any help greatly appreciated.
  • radair Copper 847 posts since
    Nov 28, 2001
    Currently Being Moderated
    Oct 18, 2002 12:00 AM (in response to minerj-disabled)
    VB Custom Component - Observations and Questions
    >3) As noted elsewhere, the
    >controls in the ActiveX
    >component do not print
    >properly when printing the
    >MathCAD sheet.

    If your control is just a text field, it will print fine. The problems occur when the control uses windows components (buttons, text boxes,...). These components, in general, do not properly draw themselves to anything but the screen (print preview is not the screen as far as a control is concerned). Mathcad follows the Microsoft guidelines for printing which is the main problem. Fudging this is a big headache which I hope will be addressed.

    >4) The ActiveX control does
    >not scale properly when
    >changing the Zoom
    >magnification. I presume I
    >could included resizer code in
    >my VB component and
    >interaction with the Ambient
    >properties of the MathCAD
    >environment, but this is a lot
    >of work when I don't really
    >want the visual interface
    >anyway.

    The control is responsible for changing its size, not Mathcad. The control gets a notification that the control environment has changed. What it does with that notification is up to the designer. Having said that, I'm not sure that VB gets sufficient info to properly resize.

    >5) The imbedded Component
    >seems very fussy. I keep
    >getting many voodoo "An
    >internal error has occurred"
    >messages, and, of course, I
    >have no idea what is going
    >wrong. After getting the
    >message, if I execute again,
    >the Component seems to work
    >fine without complaining.

    Usually these types of errors mean your control has "crashed" internally - commonly overrun a matrix size. You should be able to run your control from the VB debugger to find those types of errors.

    >6) The documentation and
    >samples provided with MathCAD
    >2000 Pro
    >

    The documention you need is a book on visual basic ActiveX controls. The basic help files will be in the VB documentation, not Mathcad because this is a Microsoft tool, not a Mathcad tool.

    >Questions:
    >1) Can anyone give me insight
    >into why I am getting these
    >"An internal error has
    >occurred" messages and how to
    >avoid them?

    Try running the control from the VB debug environment and single step through the code. Also, note that VB controls should be set to binary compatability if you want old worksheets to run with a newer version of the control.

    >2) My objective is to obtain
    >the processing speed of
    >compiled code, not to create
    >custom user interface controls
    >for MathCAD. Is it feasible to
    >write VB .DLLs instead for the
    >same purpose, and avoid the
    >user interface hassles?
    >Writing C / C++ .DLLs is
    >beyond my skill set. If so,
    >any insight into how the
    >vector / matrix data in
    >MathCAD can be passed to /
    >from functions contained in my
    >VB .DLLs?
    >

    C/C++ dll's for doing basic matrix math are much easier to write (in my opinion) and run much faster than VB ActiveX code. The VB dll's (ActiveX controls are a special dll) get their advantage when you want to display graphical data on the screen. Do you have a test case in mind?


    Robert
  • Copper 685 posts since
    Nov 5, 1999
    Currently Being Moderated
    Oct 18, 2002 12:00 AM (in response to minerj-disabled)
    VB Custom Component - Observations and Questions
    On 10/18/2002 12:33:00 PM, minerj wrote:
    >Questions:
    >1) Can anyone give me insight
    >into why I am getting these
    >"An internal error has
    >occurred" messages and how to
    >avoid them?

    Can you post the activeX control, and a Mathcad worksheet that uses it? You would be much more likely to get an answer if you did.

    Richard
  • GuyB Bronze 445 posts since
    Jun 1, 2007
    Currently Being Moderated
    Oct 22, 2002 12:00 AM (in response to minerj-disabled)
    VB Custom Component - Observations and Questions
    Hmm. I have not written VB DLLs, but have written a lot of C/C++ DLLs. That said, I suspect the cause of the errors is similar to those I've seen.

    I see that kind of behavior when: 1) I have a bug in an array size (trying to read beyond the allocated memory), 2) haven't set up the error handling strings properly, and 3) in earlier versions of Mathcad, when their own memory allocation routines had a bug.

    Most of the time, it's a bug in the user code, trying to retrieve invalid data. However, if you've debugged the algorithm, then you may be running into a Mathcad 2000 issue.

    If you're running Mathcad 2000, and you use their memory allocation routines, you're probably going to run into problems. There's an old thread on memory leaks in MathcadArrayAllocate() for C/C++ DLLs. If memory allocation works similarly in the VB environment, this may be your problem.

    Good luck,

    - Guy
  • radair Copper 847 posts since
    Nov 28, 2001
    Currently Being Moderated
    Oct 22, 2002 12:00 AM (in response to minerj-disabled)
    VB Custom Component - Observations and Questions
    >The ActiveX control doesn't
    >fail when I run it in the VB
    >debugger with MathCAD as the
    >driver program.
    >
    Which version of Mathcad do you have? There are some issues with VB components with versions prior to 2001i. The ones I remember are that changing the container properties such as font or background color will crash Mathcad when a VB component is in the worksheet. I also remember that some things worked fine in debug mode but not release mode. The specific error you describe does not ring a bell, but it sounds like a problem that occurs when the VB component loses focus. Do you do anything in the control at that stage? If you post the VB environment I'll look and see if anything stands out.
    >
    >Assuming that VB .DLLs can be
    >used, are there references to
    >how MathCAD data can be passed
    >back and forth to funtions in
    >VB .DLLs?
    >
    The VB dll will simply be an ActiveX control. I don't know of any other way to use VB for passing information to/from Mathcad with VB dlls. Be aware that on current versions of Mathcad you can only pass real data from the vb script back into Mathcad. This is a bug, not by design.

    >The application in question is
    >to apply rainflow counting
    >algorithms to fatigue spectrum
    >input for crack growth
    >calculations in metals. The
    >basic algorithms have been
    >programmed in MathCAD;
    >however, depending upon the
    >size of input spectrum data,
    >the calculation times can span
    >several hours. We wish to
    >reduce this to minutes if
    >possible through use of
    >compiled algorithms.
    >
    You may gain as much as a factor of 100 in speed going from VB to C or C++ depending on the specifics of the calculation. Since that's apparently not an option, I think you're stuck with using VB as an ActiveX component. Just out of curiosity, can you just program the vb script that runs the component to do your calculation rather than creating a brand new component?

    Robert
  • ptc-4128802 Copper 4 posts since
    Dec 13, 2011
    4) The ActiveX control does not scale properly when changing the Zoom magnification. I presume I could included resizer code in my VB component and interaction with the Ambient properties of the MathCAD environment, but this is a lot of work when I don't really want the visual interface anyway.

     

    Hi i'm kind of new at this, how can I get the ambient properties  from of the mathcad environment?, I mean, how can I detect that mathcad zooms in or out.

    So far I just can change the size of the font with the script.

     

    Diego

More Like This

  • Retrieving data ...

Bookmarked By (1)