Hello World!

This is my real first post in Powerbuilder. (I wrote a lot about PB and my association with it before). Like it is customary for any tutorial or book on programming to start with a program to print Hello World, I will try to do the same in Powerbuilder.

Before I jump into it, let’s some simple ones: (I am only including the actual lines and not full program code here,  please refer to the really interesting site that prints hello world in various languages – here)

In a Pascal (and Delphi) program, you can just say,

{Hello World in Pascal}
writeln("Hello world");

In C, you can do

/*Hello World in C*/
puts("Hello World!");

In Basic Language, (which contributed to Powerbuilder’s Powerscript) you can do

10 REM Hello World in BASIC
20 PRINT "Hello World!"

Coming to the more Object oriented world,

In C++ you can write,

/*Hello World in C++*/
cout << "Hello World!" << endl;

And in Java, this would be,

/*Hello World in Java*/
System.out.println("Hello World!");

Well, almost of all of them print to a console – a text based screen, like in DOS, Unix, Linux.

The same task of showing hello world to the user takes a bit more, when it comes to a windowing world (like MS windows, X-windows, Apple mac interface). The presentation becomes little more important. After all, in such an operating environment, everything is shown inside a window, so our program needs to write into one such too! In a windowing environment, simplest way to present a text is using some type of message box, which is a small window showing the text (and may be some question buttons).  Luckily windows API offers functions to create such a messagebox with ease. Let’s see how we could do the same in Java, for a windowing environment:

/*Hello World in Java -windowing version*/
javax.swing.JOptionPane.showMessageDialog(null,"Hello world!");

Swing is a package available in Java to create an application for a windowing environment.

Coming back to what we started with, to print Hello World in Powerbuilder, we could do something like above using a messagebox. Luckily PB offers a function for that – MessageBox. So, in the simplest form, we will do,

/*Hello World in Powerbuilder-Simple*/
MessageBox("Hi from Powerbuilder", "Hello World!")

Executing the Hello function
We are almost done. In all of the examples above (except BASIC which was interpreted, you just type that one line and it did print it), we need to wrap this line in a program. In the C like languages, including Java, we would need a main function to invoke our “Hello” function.

// Hello World in Java using Swing GUI
class HelloWorldSwing {
   static public void <strong>main</strong>(String args[]) {
      javax.swing.JOptionPane.showMessageDialog(null,"Hello world!");
   }
}

Main function is the entry point in various languages like C, C++, Java. This is the function that is called when the program is executed.

Powerbuilder is built slightly differently. It does have an entry point function – actually an event. This will be the open event of the Application object. Just like the class with main function becomes entry point object in Java, an Application object is the entry point object in Powerbuilder and its Open event is executed first when the application is executed. So in it’s simplest form, we simply add the Messagebox function in the application open event and just run the application. When run, this is what you will see,

Well, that’s for showing the simplest way. But a typical PB application is built not just with application object, but with one or more windows and other types of objects as well. We will see about that in a later post.

Advertisements

Comments, please?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s