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

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