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

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