Tech Articles


How to capture error messages from an ActiveX control


Normally when you use OLEObject to connect to an ActiveX control and encounter an error, you will get the generic run time error ‘R0035 – Application terminated. Error calling external object function xxx’.

 

I have run across a very simple way to capture the actual error code and message generated by the ActiveX control.

 

First, create a new Standard Class object and select oleobject for the type.

 

Next add the following instance variables:

 

ULong ErrorCode

String ErrorText

 

Then add this code to the externalexception event:

 

ErrorCode = ResultCode

ErrorText = Description

 

Finally save the object as n_oleobject.

 

In your script that calls the ActiveX control functions you will do the following:

 

n_OLEObject oleTheObj

Integer li_rc

 

oleTheObj = Create n_OLEObject

li_rc = oleTheObj.ConnectToNewObject(“TheObject.Name”)

If li_rc = 0 Then

   try

      oleTheObj.TheFunction()

   catch ( RuntimeError rte )

      PopulateError(oleTheObj.ErrorCode, oleTheObj.ErrorText)

      MessageBox(“OLE Runtime Error #” + &

            String(Error.Number), Error.Text, StopSign!)

      oleTheObj.DisconnectObject()

      Return

   end try

   oleTheObj.DisconnectObject()

Else

   MessageBox(“OLE Connect Error #” + String(li_rc), &

         “Connect To Object Failed!”, StopSign!)

End If

 

You’ll notice that in the catch section I used PopulateError to get the instance variables with the error information. I did this so I would also have the objectname/scriptname/linenumber for error logging if this were a real application.

Comments (0)
There are no comments posted here yet

Find Articles by Tag

Graph Resize .NET Std Framework BLOB Script Performance Automated Testing Android PFC ActiveX Filter HTTPClient Web Service Proxy DataType RichTextEdit Control Open Source PowerServer Web Encryption PostgreSQL SQL Server TLS/SSL External Functions PBVM Elevate Conference License IDE PowerBuilder (Appeon) GhostScript Authorization Windows OS Transaction Sort Git Error Repository Linux OS Database Connection Export JSON JSONParser Database Painter Design Source Code DevOps C# TortoiseGit JSON XML Event Handling TFS Application Branch & Merge OAuth Event UI Debugger Database Object SnapObjects Database Profile RESTClient Visual Studio File InfoMaker SVN ODBC iOS Database Database Table Schema .NET DataStore PowerBuilder OLE Export Debugging Array 32-bit PDF Debug DLL Database Table PBNI JSONGenerator SQL Import JSON Class .NET Assembly Windows 10 Icons Authentication Excel Variable RibbonBar Builder MessageBox UI Themes CI/CD API Text Icon PowerScript (PS) SnapDevelop SDK WinAPI PBDOM Stored Procedure SqlModelMapper Oracle Syntax Deployment Expression PowerServer Mobile Installation Charts Configuration Mobile Event Handler Encoding UI Modernization Database Table Data TreeView Source Control SqlExecutor COM DragDrop DataWindow Window Platform Migration NativePDF 64-bit Data Messagging DataWindow JSON SOAP Validation Trial RibbonBar PDFlib CoderObject Import Service Web API OAuth 2.0 PowerBuilder Compiler Outlook REST Bug PostgreSQL ODBC driver OrcaScript Interface CrypterObject Model Menu Azure Jenkins WebBrowser Testing