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

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