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

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