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

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