Thursday, 26 December 2013

Learn PowerBuilder Quickly - Part -1.2 Working With PowerBuilder

HI everybody
On last post I shared about very basics of powerbuilder. That’s full of theory, if I go on that way then you may feel bore about reading. So let’s we learn by theory cum Practical’s. Hope you have installed PB software in your system. Let’s we do our practicals now.
--------------------------------
Today we will do an simple project to display a message box.
First Open your PB Application.
We can open PB by going to start menu, select powerbuilder . This is one way, we can also open PB by opening Run in Windows, type pb105 [here the number 105 means the version , if you using 12.5 then use pb125].
The window will look like


Fig 1.1

You can have a look on all menu items and all icons in this window.
So that its easy to go to that one quickly.
As we seen yesterday we want to create the workspace first.  For that
                Goto -> File Menu -> New
That will look like this.


Fig 1.2

Now Press OK
It will ask for Workspace name , and the path where to store the Workspace. For our training Purpose , create a Folder with any name and Navigate that to that location and Give the name for the workspace. In my case I have created a new folder at D: Drive with the name Practicals. And the workspace name as pb_practicals.
If you done all these and press ok you will get the PB window like this


Fig 1.3

Hope you get it , no problem in this.
Now we have created a workspace.
The next concept we have studied is Application.
To create an Apllication we can go by
                File-> New         Or   Using Keyboard  CNTRL + N
When you do this you can see the same Figure 1.2 . You see there are 8 tabs in there, The first tab we already used , that’s for Workspace creation .
Now we want to go for Second Tab. When you do this you can see this window.


Fig 1.4
Choose the Application Icon located at first. It has Many Icons, we will discuss this at later.
Now Press ok Button.
You can see this window , give the name to the application
The second text box shows the Library path. The next one is Target . So we are creating , Application , target, library.



Fig 1.5

Have a look at the library path and the target path, its where they are stored. Now press ok
After you did these steps you can see the window like this



Fig 1.6

The next thing we want to create is objects. As read at last post we know about objects. Now we will create a window object. To do again do new , CNTRL + N



Fig 1.7

Now go for 3rd tab, These are the some of the main PB objects.
 in that select the window icon , and press Ok. Now a window is appeared in front of you.
As shown in the below figure move your cursor and select the Command Button


Fig 1.8

Click it and come to window surface and do one more click. Now command button will be placed in your window. By default the name for the command button is none. You can give the name to the command button by select text on the right side or in above. I show you where is those



Fig 1.9

In these two places at any one place you can change the name of the visual object.
 Now we want to do code for the command button. So that when you click on it , that will show a messagebox.  To write code to any visual objects double click of the control , or right click on the control and choose the script option.
And write down the code
Messagebox('Hi Buddy','This is Test Message')
Now we want to save what we have done. To do so , as like normal save do CNTR + S
It will ask for window name to save , and also library,  as far as we have created only one library so now no problem . but in future we are going to work on many libraries on single target , so ensure we are saving the objects at appropriate library.
And while giving the name to the objects We should Follow the Naming Rules. If you not aware of the naming standards Kindly see the Post about Powerbuilder Naming Standards.


Fig 1.10

Now we have done almost 90% of the work in this project. What else want to do???
We didn’t said to powerbuilder that , this is my window , while Runiing you should run this . So where we want to to do so.  Here comes the main thing , the Application Object.
Now close the Window , I mean the Library Window, Return back to the  Library ,got it? Or confusion , well I show what is library,


Fig 1.11

This is the Library Window. To view this can do , go to Tools Menu  ->  Library Painter , or Shortcut Key Shift + F10
Now you can see the Window what we have created.
As I said earlies we want to tell PB to which is opening window. At left side can you see the name of the window that we created , above to that and under pb_practicals.pbl there is one object is there , Every application has a application object , whenever you create a application along with that application object is created. That is the thing where we want to give the initial opening codes.
Lets Double click that

This Apllication object has 6 Events in it
Open    
Close
Connectionbegin
ConnectionEnd
Idle
SystemError
We want to write our code in Open Event

So we have already double clicked the Application object rite. By default it will be in open Event. Lets write this code in there
Open(w_main)

Save it . -> CNTRL + S
That’s all Project Ready. Now we want to Run it, To Do so Use CNTRL + R.
Can you see this window?


Fig 1.12

Click on the Button
Can you see this ??

Fig 1.13
Fine , our First project is over.
Rite now we have created workspace , application Target, library , window object , button.
Do it again for practice about creating these basic things.
Here I have stated very few things. By default PB has a excellent help file. When you press F1 it will display the help window . in that search for the terms what we have studied. And gain extra knowledge . will meet at next post.


--------------------
Regards
Pushparaj


No comments: