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

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