Utilizing the .NET Framework System Diagnostics Code in PowerBuilder.NET Programs

This short article will show you how to adapt Microsoft .NET Framework C# code examples for use in PowerBuilder.NET.  I’m using the System Diagnostics in one of my non-visuals to log errors and application problems to the Windows Event Logs.

Adding the USING statements in PowerBuilder.NET

When adapting .NET code for PowerBuilder the first thing you will notice is that the using statements will not work in PowerBuilder.

The using statements get added via the code menu, similar to if you were adding an instance variable to a window, but instead of choosing instance variables you choose “Namespace / Usings”.

This is how my non-visual user object looks after adding “System” and “System.Diagnostics”


using System;
using System.Diagnostics;
string sSource;
string sLog;
string sEvent;
sSource = “dotNET Sample App”;
sLog = “Application”;
sEvent = “Sample Event”;
if (!EventLog.SourceExists(sSource))      {
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Warning);   


The equivalent code in PowerBuilder 12.5.NET is listed below. For the most part it is relatively clear, the main differences are using NOT instead of the exclamation, eliminating semi-colons, and using the exclamation on the enumerated “Warning!” value.

// using statements added via Declare menu

string lsSource = ‘dotNET Sample App’

string lsLog = ‘Application
string lsEvent = ‘Sample Event’
if NOT EventLog.SourceExists(lsSource) then
     EventLog.CreateEventSource(lsSource, lsLog)
end if
EventLog.WriteEntry(lsSource, lsEvent, EventLogEntryType.Warning!)


No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *