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

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