PowerBuilder: Article

A Snippet Here, a Snippet There

A Snippet Here, a Snippet There

Once upon a time there was a source code editor called "Brief." Okay, so it was DOS-based and had an ugly interface. However, it had one feature I truly loved, a "code snippet" manager.

You could have your favorite block of code inserted into your source with a few keystrokes. Eventually, I stopped writing Clipper code and started using PowerBuilder, which didn't have this built-in feature...until now.

The "Clip Window," toggled on and off via a new icon on the PB8 PowerBar, allows you to store your favorite "clips" of code and drag-and-drop them into your scripts. The name Clip Window refers to the clip being imported and exported via the Windows clipboard.

To store a piece of code, simply highlight it in your script, then drag-and-drop it onto the Clip Window pane. You'll get a new line entry with a blinking cursor. Type a name into the edit and you're done! You should see your code name and the first few characters of your code block in the column next to it (see Figure 1).

To use this code, click on your script where you want the code clip to be placed, mouse over to the Clip Window, and click on the clip you want to use. Drag-and-drop this onto your script windowpane and you're finished.

To help get you started, type in the four code clips in Listing 1, highlight one code block, and drag it onto the Clip Window. Save each, and you'll have started your own library of code clips. Here's a brief note on each code block:

  1. Commit SQL changes: This is a staple for anyone coding DataWindows or inline SQL. It's the error-trapping block that should be used after any DataWindow Update or SQL Data Modification Language statement (except SELECT). Due to distributed processing, it's highly recommended that you use the ... USING <transaction object> suffix on every SQL statement that allows it. This way, you ensure you are communicating with the right transaction object. Leaving the suffix off, which you'll often find in legacy code, defaults to using SQLCA only.
  1. Multiple-Select with toggle: Seasoned developers will easily recognize this code. It allows a selection of multiple rows. If a row is already selected, it toggles it On/Off.
  2. Single-Select with toggle: The same as No. 2, except you can only make single selections.
  3. Retrieve DataWindow data: The code for my ue_postopen event to retrieve a DataWindow.
  4. Update DataWindow: The steps needed to update the DataWindow, including performing an AcceptText() prior to the Update() and a COMMIT after the Update, followed by checking the SQL return code.

More Stories By David Hart

David Hart is a former Sybase Tools and Database Instructor. He is a certified PB developer and certified ASE DBA from Rancho Cucamonga, CA. He is currently on contract assignments in Southern California.

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.