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

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