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

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