|By Richard (Rik) Brooks||
|October 8, 2012 12:45 PM EDT||
I'm considering changing my emphasis in my column. Since speaking with some people at Sybase I am convinced that PowerBuilder is poised for a mighty comeback. The fact is that still today PowerBuilder is by far the most productive development tool available. It eclipses all the rest. An experienced PowerBuilder programmer is demonstrably more productive and can finish tasks faster than C# or even VB.NET.
So why is .NET used by more companies?
Mine would just be a guess and in fact, the answer is irrelevant. I'm here to tell you that Sybase is making an obvious push to regain some of the ground that it lost. The programmer who positions himself as a PowerBuilder expert today will benefit tomorrow.
I am going to split my writing. This month I'll do another article on the classic DataWindow. That architecture is not going away. I've discovered that many companies are still maintaining code that was written 15 years ago. What other language can make that claim?
I'm going to support those programmers who are using Classic PowerBuilder with articles like this month's. I'm also going to start a series of articles on returning to PowerBuilder programming after a hiatus of several years. I'm going to point out the changes that have occurred since, ohhhh, about version 6.5 and how we can benefit from them; what they are and how to use them.
I found this need when I was reading an article by Bruce Armstrong a couple of months ago on Web Services. He simply lost me in the dust. I found there was fundamental information that he assumed that I knew that in fact I did not.
Time to bridge the gap and I'm betting there are a lot more people out there like me.
With that in mind let me use this article to provide a little fundamental knowledge about Classic PowerBuilder. I'm going to pass on some oft-used techniques and next month we'll begin exploring how to best catch up.
Using the Database Painter to Make Your Life Easier
Let's begin with something that most of us have ignored for years. We normally let the DBA handle the database. It's not our job; we are on the front end.
Well, a few simple edits in the database painter can greatly enhance our productivity and provide a seamless conformity in look and feel.
I would first like to address Edit Styles. Have you ever encountered an application that used date edits as MM/DD/YY and then another application used MM/DD/YYYY? I've seen some applications that used MM/DD/YYYY and in another application (in the same company) used the European DD/MM/YYYY.
Wouldn't it be nice to allow your user to type in MM/DD/YYYY but display "Saturday, Jun 1, 2012"? You can do that with no code whatsoever. Not only can you do that but you can do it for every application on which you work. You simply store the Edit Mask AND the Display Format in the database. Then you can go to your table definition and assign the edit mask and the display format to the column. From then on every time that the column is selected in the DataWindow painter it will pick up the edit mask and the display format automatically.
We begin by writing a bunch of extended attributes. You can access them by opening your database (not DataWindow) painter then going to "View->Extended Attributes" as shown in Figure 1.
There are three kinds of extended attributes: Display Formats, Edit Styles, and Validation Rules. Let's take them one at a time.
A display format defines what the column looks like in the DataWindow when it does not have focus. You may recall our example of dates above; the display format would have been "Saturday, Jun 1, 2012".
I'm not going to go into detail about how to work with display formats. That information is readily available to you, just google "powerbuilder working with display formats" and the Sybase page will be right at the top.
I will point out a few of the more common and useful tips though.
@ is a wildcard in a string. You could (and should) define a display format for long and short telephones. Here they are:
Long "(@@@) @@@-@@@@"
Go ahead and load the Extended Attributes as shown in Figure 1. A panel will appear in the database painter that looks like Figure 2.
Right-click on the Display Formats and then click New.
Enter the values as you see them in Figure 3.
Note that you used the hashmark for wildcards. That's because this is a display format for a number column. Let's do the one for the short number - look at Figure 4.
As you can see we simply remove the area code and parenthesis, which brings out a good point - everything other than formatting characters are treated as literals.
I have four different ones, Long and Short Telephone Strings and Long and Short Telephone Numbers.
You might also want to store a display format for SSN numbers (###-##-####)
You could have one for money, $#,##0.00
Or if you like $#,##0.00;[RED]($#,##0.00) will give you a money style with dollar signs, commas and decimals in the right places and will give you a red number, again formatted correctly, if it is negative.
This is all without the programmer having to do anything at all.
Again, I don't want to just repeat these formats when you can easily look them up, but maybe one or two to help convince you that you should take the time. How about this for dates? (see Figure 5.)
You can also use the date formats that the user has set up in his Windows environment. You can use [LongDate], [ShortDate], or [General] (which is the same as ShortDate). The list goes on and on.
The Edit Style
An Edit Style is similar to an Edit Mask control. It will allow the user to type in a value while automatically skipping around formatting characters.
Creating new edit styles are very similar to the Display Formats.
Using the Edit Style and Display Formats
Okay, let's put this together into something useful. Let's create a display format for a DateTime (see Figure 6).
That gives us a really large DateTime, clearly not one that we want to use as an edit mask, so let's create a separate edit mask as shown in Figure 7.
If this works we should be able to go to the properties of any DateTime column in any table and set the Display Format and the Edit Styles and in effect automate them.
First open any table (using the Database Painter) that has a Date Time column. Find that DateTime column, then right-click on it and select Properties. Figure 8 shows you the properties. I've highlighted the tab pages for setting both the Display Property and the Edit Mask.
Let's click on the Display Property (see Figure 9). You can see that the date time that we created is available.
Now click on the Edit Style tab page and you can set the edit style.
The final test is to create a DataWindow that includes that column. You will find that both the Display Format and the Edit Style are automatically set for you. Using this process you can encourage conformity in your applications. It doesn't matter which application it is, if they attach to this database you will automate their values.
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- Creation and Consumption of Web Services with PowerBuilder
- Cloud People: A Who's Who of Cloud Computing
- DDDW Tips and Tricks
- Working with SOA & Web Services in PowerBuilder
- Cloud Expo 2011 East To Attract 10,000 Delegates and 200 Exhibitors
- Dynamically Creating DataWindow Objects
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form