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

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