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

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