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

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