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

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