Helping Developers Master PowerBuilder Classic and .NET

Yakov Werde

Subscribe to Yakov Werde: eMailAlertsEmail Alerts
Get Yakov Werde: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Related Topics: Enterprise Architecture, Enterprise Application Performance

Blog Post

Writing to the Console in PowerBuilder 12.5 .NET

Why can’t a PB program directly write to the console in a displayable manner?

Yesterday I taught an intro to PowerBuilder .NET 12.5 session.  Part of the presentation had me comparing the.NET IL code inside an assemblies generated from code written in C# and PowerBuilder.

The C# code, after performing a simple arithmetic calculation echoed results to the console using these two lines of code

namespace CalculatorExample
class Program {
static void Main( )   {
Calc c = new Calc( );  //create the object
int ans = c.Add( 10, 84); //call the method
System.Console.WriteLine("10 + 84 is {0}." , ans);
System.Console.ReadLine( ) ;    }

class Calc {   //define a wrapper class for the method
public int Add( int x, int y)
{return x + y ; }  }

In PowerScript, ordinarily, I echo results using a Messagebox call, but yesterday, I thought I'd "step out on the limb" and echo output to the console using the same NET Framework class methods C# programmers use.

The equivalent PowerScript Code (slightly refactored) looks like this:

n_calc Calc
Calc = create n_calc
integer addend1=10, addend2=84, result
result = Calc.add( addend1, addend2 )
System.Console.WriteLine("{0} + {1} is {2}", addend1, addend2,result)
System.Console.ReadLine( )

I opened a console window and ran the app from the command line

The first run threw this exception:

Hmm, that's the ReadLine call.  I removed that line and ran it again

Hmm, no console output.  Then a clever programmer suggested that I pipe the output to a text file and then type the file.

Wow! Strange! What a trick! It worked! Here's the console output.  You can plainly see that we did get results, but for some reason they didn't display to the console device.  Only through outstream redirection was I able to capture the output.

I'd be mighty pleased if someone in engineering could explain this behavior.  Why can't a PB program directly write to the console in a displayable manner?   Why does ReadLine throw an exception?

More Stories By Yakov Werde

Yakov Werde, a 25 year IT industry veteran, is a member of TeamSybase and the newly formed Sybase Customer Evangelist Team. Yakov is a recognized author, speaker and trainer who has been designing and delivering PowerBuilder, .NET, EaServer, Web App Development, and Java training for over 14 years to corporate, military and government developers. Prior to discovering his aptitude as an educator, Yakov worked as an architect, project manager and application coder in the trenches of application software development. Yakov holds a Masters in Education with a specialty in instructional design for online learning from Capella University and a BS in math and computer science from Florida International University. Yakov, managing partner of eLearnIT LLC (, authors and delivers workshops and web based eLearning tutorials to guide professional developers toward PowerBuilder Classic and .NET mastery. Follow Yakov on Twitter as @eLearnPB

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.