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

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