123 Tips & Tricks Of PowerBuilder

Collection PowerBuilder Tips & Tricks. Get From The Internet

Tips 1: Changing DataWindow object by code methods

Tips 2: Open dynamic window approach

Tips 3: Displays a consistent style with the Windows operating system About dialog. First, the following statement external function:

Tips 4: How COLUMN display style between EDIT, DDDW, DDLB switch between

Tips 5: Few records you want to print selected in the dw_1

Tips 6: Achieved when the cycle is terminated by clicking the button loop

Tips 7: SQL statement calling convention

Tips 8: Modify function by modifying multiple tables simultaneously

Tips 9: Click Edit marquee in which the content

GetFocus Event Write code: This.SelectText (1, Len (This.Text)). Save Running, Do Not Get what we want Effect. Think Of an alternative approach: To pbm_bnclicked For the Event ID, Create a single-line EDIT box custom Event ue_clicked,
code Is: This.SelectText (1, Len (This.Text)),
code GetFocus Event changed: This.Post Event ue_clicked (). After the Save operation, the Effect came out!

Tips 10: How to get the number of characters in the string

Tips 11: Finally, li_num is the number of characters

Tips 12: DW support press Ctrl or Shift-click to select more than Line

Tips 13: DW queries change conditional statements

Tips 14: Datawindow: Tips to save data

Tips 15: Select to delete records

Tips 16: Sorted by a field

Tips 17: Control DATAWINDOW in the number of rows displayed per page

Tips 18: How to achieve data window data automatically wrap

1) Open the Datawindow Object In the Datawindow Painter.
2) Double-click the mouse On a column In the need To Set up Automatic fold Line, bounced off the properties window For This column.
3) Select the Position tab, Select AutoSize Height checkbox.
4) Select the EDIT tab And Uncheck Auto Horz Scroll checkbox.
5) click the OK button To Save your changes.
6) points Detail Band (ie Write Long belt Detail gray), And click the Right mouse button And Select properties … menu Item.
7) Select the AutoSize Height checkbox.
8) click the OK button To Save your changes.
9) Save the Datawindow.
Note: the characters together (With no punctuation Or spaces), the System will be considered as a word, does Not automatically wrap,
English Is also True …… DW window wrap If there are characters, Then it will be necessary To wrap the intermediate spaces, otherwise how To Set up will Not work. For example, you
If you want To fold In the First 20 Rows, you First determine whether it Is the First 20 characters, If Not To put a Space After the First 20, If the characters In the
the First 19 spaces. determine whether the characters In the ASCII code can use it To determine whether it Is greater than 127.

Tips 19: By conditions on color-coded data in a row

Tips 20: PB simultaneously connect to multiple databases, such as connecting SQLServer2000 and Oracle8

Tips 21: Connection Oracle8i and 9i of

Tips 22: Retrieving data rows in a row plus

Tips 23: DataWindow, press the enter key to achieve tab function (in Enter event data window)

Tips 24: send usage: Send (handle, message #, lowword, long)

Tips 25: Reset search statement data window

Tips 26: PB standard sql statement calling

Tips 27: PB standard cycle call sql statement

Tips 28: Generic Script window open event

Tips 29: Query button Generic Script

Tips 30: Add button Generic Script

Tips 31: Delete button Generic Script

Tips 32: Save button Generic Script

Tips 33: Print button Generic Script

Tips 34: Export button Generic Script

Tips 35: Import button Generic Script

Tips 36: Exit button Generic Script

Tips 37: Generic script calling process

Tips 38: PB some controls Chinese display problems

If PB’s ListView can not properly display Chinese, you should set the ListView’s FontCharSet property Into Other types. the Export ListView Where the Object Into the Source code. Find ListView definition section In the Source code, which will FontCharSet property Into DefaultCharSet! If Other controls PB corresponding phenomenon also occurs when the same adjustments To its FontCharSet properties. General Speaking For Simplified Chinese fonts In Chinese WINDOWS environment should be Set To DefaultCharSet !. Display Chinese Control In Question it’s FontChatSet property forcibly set to DefaultCharSet! Should be no problem. Or change the font !!!

Tips 39: Data type conversion

Conversion Between numeric types automatically By the System, usually converted To high-level accuracy based On the operator To participate In operations.
Precision numeric types From high To low priority as follows:
Double ← Real ← Decimal ← UnsignedLong, Long ← UnsignedInteger
String To numeric Type Conversion functions:
Integer (str), Long (str), Real (str), Double (str), Dec (str)
numeric To String Conversion Function Is:
String (Number, Format), Number Is Any numeric Type, Format After Format Conversion instructions can usually be omitted.

Tips 40: Pronouns

This: This representative Of the window, the user Object, menu, Application Object Or Control itself, which represents the Object being To whom To Write Event handlers.
Parent: Parent refers To the window Where the current Control.
ParentWindow: ParentWindow representative runtime menu window Where the pronoun used only In the Event handler menu.
Super: when writing a Control sub-objects Or Object, the child Object can Call the Parent Object’s event handler, the program can directly use the Name Of the Parent Object To Call them, can also be used To refer To Super pronouns. For example, when you want To Call the Parent Object’s Clicked event handler, sub-objects can be written: Call Super :: Clicked

Tips 41: System of five predefined global variables

SQLCA, sqlda, SQLSA, Error, Message

Tips 42: Relationship in PowerBuilder and RGB color values between the values as follows:

Color = R * 256 * 256 + G * 256 + b

Tips 43: There are fourteen kinds of standard data types

Blob binary large Object, used To store large amounts Of Data, such as images, large Text, etc., such as: Blob {100} ib_test // length 100
Boolean Boolean, Boolean variable has only two possible Values : True Or False
Char Or Character, a single ASCII Character
Date Date, including the Year (1000-3000), Month (01-12), 1999 (01-31)
DateTime Data Type DateTime Date And Time, only For Database Access
Dec Or Decimal, signed Decimal Number, maximum 18 Precision, such as: Dec {2} ld_test // 2-bit precision
Double floating-point Number With Sign, 15 significant digits
Int Or Integer, 16-bit signed Integer
Long 32-bit signed Integer
Real signed floating Point Precision 6
String String Type, ASCII characters used To store an arbitrary Length Of 0 To 60,000 (16 environments), 32 environment Length Limited only By the capacity Of the System. when the program writes directly To the String, use single quotation marks (‘) or double quotes (“) to enclose the string the Default Value Is an empty String (“”)
Time 24-Hour Time, including the Hour (00 To 23), points (00 To 59), Second (00 To 59) And the Second Decimal place (up To six), Range From 00:00:00 To 23:59: 59: 999999
UInt Or UnsignedInteger, UnsignedInt, 16-bit unsigned Integer ranging From 0 To 65,535
ULong Or UnsignedLong, 32-bit unsigned Integer ranging From 0 To 4,294,976,295
Any Type Of Any variable In Order To know the Type Of stored Data, you can use the Function ClassName ()

Tips 44: How pictures will be stored into the database

define a Bolb variable lb_file, the file Read lb_file, With insertblob Or UpdateBlob On OK

Tips 45: Variable scope

Global Variables: the entire Application can Access, its scope Is the entire Application
Instance Variables: the Object Is associated With, only be used For the Object Instance Variables defined In the Event handler Or Function Of the Object.
Instance Variables when it Is associated With an Object created Is opened, when it Is closed To disappear
Shared Variables: a Static variable, which means Not only share when it opened again After the Object Is closed Object variable remains closed Value, But also means keeping multiple instances Of the same Value With the same Name In a Class Shared Variables
Local Variables: the use Of its Event handler Or Function described In its scope Is Limited To the description Of its program segment, Any segment Of the program Places can Access Local Variables, But Other programs can Access This section block Local Variables. After Running the program, enter when a program segment, the System automatically allocates memory For Local Variables, when you Exit the program segment, the memory Of Local Variables Is released.

Tips 46: exit, continue, return

1.Exit (Exit Loop): Do … Loop And For … Next Loop statement, when we wanted To quit In the middle Of the cycle when the Exit statement, Control procedures go To the statement After the Loop, In the Case Of nested loops, Exit statement To Exit the current Level circulation, But Not All cycles.
2.Continue (continued circulation): In the body Of the Loop Do … Loop And For … Next statement, After encountering Continue statement, After the End Of the cycle does Not Execute Continue statement All statements before, And began a new Round Of circulation.
3.Return statement: Return Control To the user Or the calling Function Places. (when the termination Of the Application you want To Run, use the Halt statement), the Immediate termination Of the Event processing execution Of the program Or Function, the Control Is returned To the calling program when the Return statement at the Event handler And a user action triggers the Event After the treatment program, the implementation Of the Return statement, which immediately terminates the execution Of the Event handler And waits For the user’s next operation when the program when calling a Function Or Event handler, After executing the Return statement, which immediately terminates execution Event handler Or Function, And To Control Is returned To the calling program.
4.Halt {Close} statement: Halt statement Is used To terminate the Application To Run when Halt Close statement With no Options, the statement immediately terminate Running applications.; when Halt statement With Close option, After execution To the statement, the Application To Execute the Application Object Close Event handler, And Then re-terminate the Application.

Tips 47: DataWindow Buffer

Primary buffer, Filter buffer, Delete buffer, original buffer when we Read the Data From the Database, All Data will be placed In the main buffer (Primary buffer), And will put a Copy Of the original Buffer (original buffer) within In the Data window we can see the Data the main buffer (Primary buffer) within Any Data processing are also doing the main buffer For Data processing, But remember, no matter what we Do the Data In the buffer zone Of Any treatment, Unless we Run the Update () Function, no changes To the Data In the buffer, For the back-end Database without Any Effect.

Tips 48: How to generate a fixed-length front plus zero digits, for example: 12 generation “00012” 1234 generation “01234.” The method is simple:

Tips 49: row represents the number of rows, col represents the field name, val represents the value

Tips 50: Read data

Tips 51: How to Grid-based datawindow into Tabular type

Export Data window Into .srd file, use Notepad To Open the processing = 1 Into processing = 0

Tips 52: Yield () function

Yield () Is a Function Not used To PowerBuilder. However, a large Loop In the process, If the user wants To perform half By clicking a button Or menu To Exit, Then it must use To Yield () Function, otherwise the program will complete the entire cycle will be executed After Respond To the click Event Of the button Or menu. the Yield () Function In the middle Of the Loop body. So Find that during the execution Of the Loop has something new Pieces Of messages In the Message queue And returned immediately To Respond.

Tips 53: sqlca.SQLCode

when Using Embedded SQL For each SQL command you should Run a Check once the Transaction Object attributes SQLCode, rather than wait Until All SQL command has finished Running And Then go Run a Check Transaction Object SQLCode properties. when the Function we use the Data provided By the window, the Do you want To remember To Check SQLCode To determine whether the Run was successful. But To every Function In accordance With the Value Of the Return Run To determine whether To Run Success.

Tips 54: To ensure the Success Of the Data stored

Tips 55: In PB how to open a file (such as .txt, .doc), just like in Explorer, double-click to open the file the same

Tips 56: Insert a row after a default value to the default value but do not modify, CloseQuery event does not excite method

Tips 57: Value of a column with a data window is retrieved based on the value of another column (on itemchanged event in DW)

Tips 58: Dynamic DataWindow

Tips 59: Read multiple rows of data

Tips 60: Dynamic SQL (There are four types)

Tips 61: Get the display value of the pull-down data window

Tips 62: Previous column method of fixing the datawindow, for example, the first column called “id”, fixed the column and started to show from the second half of the next column:

Tips 63: Print data window last one approach

Tips 64: When the edit box to get focus automatically selected content

Tips 65: If more than 23 this month, will be the 1st time is set for next month, otherwise take the current time

Tips 66: Allows the user to modify the newly added records, and the records retrieved are not allowed to modify.

Tips 67: Ole object, such as when using the communication with the Word, how to avoid multiple Word and other programs to start

Tips 68: Call screen protection method in PowerBuilder

Tips 69: Get path when the program is running

Tips 70: Editing style columns dynamically set in the program for the pull-down data window (DropDownDataWindow)

Tips 71: Incremental search function realization

Tips 72: How in the program written for the database BLOB

Tips 73: How to remove content DDDW the Display Column of

Tips 74: Shielded window ALT + F4 keys

Tips 75: How to achieve in PB delay

Tips 76 : With the following expression can be obtained in a certain group recorded line number:

Tips 77: Call the API function steps

Tips 78: GRID format data under the window, according to the actual situation of each row to control the background

Tips 79: Achieve the data window of a column / row is displayed as a specified color

Tips 80: In the data window How to hide a computing unit

Set In its properties \ expression \ visible property “IF (1 = 2,1,0)” on it.

Tips 81: Hyperlink

Tips 82: get value of the expression

Tips 83: Commonly used API functions by example

Tips 84: PB of SHELL command

Tips 85: PB key code constants described

Tips 86: PowerBuilder system tables

Tips 87: In the datawindow after which press the Enter key, the focus moves to the back of the field, such as from the last movement, then automatically jump to the next line

Tips 88: Window among the enter event

Tips 89 : How in the program for datawindow plus computational domain or line

Tips 90: A window redraw the screen in the middle of the function

Tips 91: How to get the path of the current application

Tips 92: Get the current name of the computer

Tips 93: Get the current path

Tips 94: How to configure an ODBC data source code

Tips 95: How to build such a function it

Tips 96: Grid window in which, in a column does not allow editing a column allows editing

With the following method, you can Not very convenient, what they want it
Method one:
In the DataWindow, Between the column And the column when Using the Tab key to move, is based on the DataWindow Tb Values For each column is Set to be moved.
When a column of Tab is 0, this column can Not be edited, so that users can Not add, Delete, change And other operations. It can be a column of Values Tab is Set to 0,
This column is Set to allow non-editable.
Follows (Set columnname For the DataWindow column name to be Set to non-editable):
dw_1.setorder (“columnname”, 0)
Or modify data In the script window with the following statement:
dw_1.modify (: columnname.tabsequence = 0 “)
Or dw_1.modify (“#” + string (number) + “. Tabsequence = 0”)
The advantage of this method is easy to realize, the drawback is Not allowed to move the column. Grid-style DataWindow that must Not checked
column moving, otherwise it will cause confusion when you press the tab key sequence.
Method two:
You can View the edit column properties In the properties View style style. To Set a column can Not be edited In the column edi style = “edit” In
Select the Display only;
Or Script window With the following statement be Modified:
DW + 1.Modify (“columnname.edit. displayonly = Yes)
Or dw_1.Modify (“#” + String (Number) + “. Edit.displayonly = Yes”)
If the column back To editable In the EDIT Style Of the column = “edit”, And Uncheck Display only;
Or Script used In window
Modify the following statement:
dw_1.Modify (“columnname.edit.displayonly = No”)
This method Is very simple, But also does Not allow the column To Move.
Method three:
Datawindow With the Clicked Event Of the method can be implemented To protect the column. If a column can Not be changed, you can Set R otect = 0. Namely:
dw_1.Modify (“columnname.protect = 0”)
Or dw_1.Modify (“#” + String (Number) + “. Protect = 0”)
To the column To be changed, Set protect = 1, Namely:
dw_1.Modify (: columnname.protect = 1 “)
Or dw_1.Modify (“#” + String (Number) + “. Protect = 1”)
This method does Not affect the tab Key To Move, users can pull the column, But also In the Application process To decide which column can be edited, which column Is Not edited.

Tips 97: Data Sheet d_query have a data column id, set to DropDownDW format and linked to another data table d_info (id, name).

Tips 98: Window within w_gcde, into a DW_1, how to get the contents inside yuonghu_id column dw_1

Tips 99: Save the report to excel table

Tips 100: PB in how to write data to EXCEL table has a fixed format

Tips 101: Save the data window for generic functions excel (decision wonderful)

Tips 102: value of the expression

Tips 103: String into an array

Tips 104: PB in the TreeView control using techniques (sweep blind)

PowerBuilder TreeView Control In a tree tour, similar To the WINDOWS Explorer, which Is characterized By tree-level information items were Structure, can Show more clearly the main, a breakdown Of the relationship, the operation Is very convenient. it can be used In conjunction With the Datawindow Application, a provide information classification System, one To provide specific information To achieve even beads Pitt together wonderful Effect. it Is especially suitable For multi-level classification Of information seized Faso, Is a multi-level menu can Not be more than Like, its manifestations By the program designers And the majority Of users In many Application software can see her heroic.
In PowerBuilder, Application TreeView Control Is much more complex than the Other controls, somewhat at a loss when you are new To it often. However, If the mechanism To figure out If it, it Is Not hard To grasp things. here i combine Changbai company books classification And retrieval Instance, the TreeView use controls, And we explore. First, the Application Of the General steps TreeView Control
1, the establishment Of an Application, And Set a good interface With the Database, which Is a prerequisite For the operation Of the Database.
2, built an Application window W_1 In the Application, adding Datawindow Control Object named dw_3 And dw_4 two On And one In the Name TreeView Object TV_1’s.
3, Modify dw_3 property
General: the Datawindow Object Datawindow called DW_date Fill In the Name Of an existing (Note: it Datawindow Control Object Is different), For spanning tree View Item, Set its Visible items are Not Visible.
4, Modify dw_4 property
General: the Datawindow Object Datawindow Object Name To Fill an existing named DW_TS For Display Check out the specific content.
5, edited TV_1 properties
TreeView tree View Item can Not be directly edited, the program must be written In the Script.
picture: picture Name added In Four different icons To represent the tree View Of two levels (one, two), two kinds Of State (Not Selected, Selected).
General: can be Selected depending On whether the Application settings, including:
Delete Items: whether to allow the operation to Delete entries.
Disable PragDrog: drag And drop operation is allowed entry.
Edit Labels: whether to allow the operation to change entries, click the title entries. Show Buttons: whether to display the entries put Buttons, there is shown the relative expansion And contraction.
Hide Selection: when the control loses focus, the selected item is displayed with high brightness.
Show Line: whether Between entries plus one vertical bar.
Lines At Root: All entries In the root zone is connected By a vertical bar.
Indentation: the child entries shrink relative to the right schedule parent entries.
6, The Script writing TV_1
Here is the key to the TreeView control is difficult.
Two, TreeView control information form And Create
Tree View item TreeViewItem TreeView control is the basic unit of information, And generates a tree View items are generally two ways, one is Mr. Cheng root layer View item, And then dynamically generate lower View items In the application, the other is the tree View of All time And a. Each of the two methods There are advantages, chosen according to the specific circumstances, the latter method is used In this example.
1, the main properties of the tree View item TreeViewItem
Label: String type, display information tree View item.
Data: Any type, the internal value tree View item.
Level: Integer type, tree View item level In the tree View.
Children: Boolean type, which determines whether the next level (as shown In the title).
PictureIndex: Integer type, when used In the non-selected icons In the icon queue number.
SelectedPictureIndex: Integer type, when used By the selected number of icons In the icon queue.
2, the functions used to generate entries TreeViewItem
InsertItemFirst (): will be added as the first item
InsertItemLast (): will join the item as the last one
InsertItem (): will join the item Into the back of the specified items
InsertItemSort (): the Order placement.
3, TreeView common event
Constructor: This event is triggered when the control is created, can be constructed here TreeViewItem.
Click: Click TreeViewItem item, Execute the query process.
Double Click: Double-click the TreeViewItem item, Execute the query process.
ItemPopulate event: This event when entries For the first time launched a TreeViewItem Trigger, while the system will Trigger the
TreeViewItem item handle handle passed over By the arguments. It is mainly used to generate the underlying information item corresponding item. Mainly used For the first Ways.
Third, the event code A tree View control TV_1 the constructor event code wanqi 1999.6.28

Tips 105: Lowercase to uppercase Amount Amount

Tips 106: Pb in custom printed pages long

In the case of continuous paper to print the data window, you need to customize the printed pages long, In Order to ensure the correct printer paper feed without human intervention,
Continuous printing. In PB shall call external functions to customize the length of the paper, more cumbersome. This paper presents a direct printer Control method is simple to achieve page-long Set.
First, prior knowledge
Communication Computer And printer Using the ASCII code, which includes the standard ASCII code printable characters And non-printing characters (control codes), The printer uses control code to customize the printer. Most printer instructions use control codes escape sequence code as the first of its instruction sequence.
Here are a few instruction code sequence used In this article:
Set the line spacing (line spacing) 8-inch
ASCII code ESC 0
Decimal 2748
Set In units of pages long
ASCII code ESC C n
Decimal 27 67 n
Where n is the number of lines per page range (1-127)
Two, PB control the transmission And custom-page code of realization
In PB to achieve By sending control codes to the printer function Printsend (printjobnumber, string, {zerochar}).
The parameters are defined as follows:
printjobnumber: By printjob () Function Returns the Number Of Print jobs;
String: Control String, use the ASCII code;
zerochar: used To Replace String Of digits 0;
because Of the String, 0-terminated String, If String contains 0, you need To use Other characters To represent 0, parameters that Do This zerochar Purposes Set, when the PB To the printer transmits a Control String To Replace the Character zerochar converted To 0. here Is the complete program specific custom pages Long Print Data window (Length Of 2.75 inches custom page):

Tips 107: pb some experience and skills

Tips 108: Datawindow to achieve a combination of field

Now assume that the customer’s province, city, address, zip code were stored in a different field, they are Province, City, Address, PC. we want To Get “Zip + State + City + address” Format, such as: “(214001) Renmin Road, Wuxi City, Jiangsu Province 1.” specific implementation as follows:
1, In the Position you want To Display To add a calculated field (Compute Field)
2, In which the Expression column Write “‘(‘ + PC + ‘)’ + Province + City + Address”
3 click OK To finish. it Is Not easy. need To remind everyone that the computational domain can only be used To Display, you can Not Modify it, because it does Not tab property, can Not Get the focus.

Tips 109: Technical Data automatically refresh the window

when we Write, such as inventory, sales And Other applications, always want the program To be able To dynamically auto-refresh inventory Or sales, For example, every 1 Second refresh. To achieve This Function as Long as we use the Time Interval Of the Data window properties (Timer Interval), when the Value Is 0 Data window Is Not refreshed, If you want the Data window To refresh frequency every Second, So Long as the Value Is Set 1000, that Is 1000 milliseconds. we can also add functionality To the Application flashing alarms. take inventory For Instance, the Most common Is when the stock reaches certain goods when a minimum inventory program should be able To automatically determine And Display a warning Color, usually Red. at This Point, we simply use the above the method Then requires the flashing On the Field, such as stocks, In which the Color properties Of the corresponding Write statement. the following code To achieve “When an item of inventory is less than 20, the program displays a warning in red blinking”
If (Store_Num < 20, & If Mod (Second (Now ()), 2) <> 0, & // once per second, even red, odd-numbered display white, i.e. background
RGB (255, 255, 255), RGB (255, 0, 0))

Tips 110: How to find the listed conditions for Datetime data types used in the DataWindow

Tips 111: Realize how not to use SELECT DISTINCT delete duplicate rows in the DataWindow SQL syntax

Tips 112: How to display line numbers in each group, respectively, in the form of packets of the DataWindow

Tips 113: How to change the font color column, this column is to remind the user to make changes

Tips 114: In the data window, remove the line, but do not filter or delete operation

RowsDiscard () Function To Do This, it Is removed To perform work In the Data window, But it can Not be removed In the row Is deleted Or Any Save the Modified nature.

Tips 115: How DataWindow display multiple lines in the Footer Band data is displayed in the first line of the current and the last line number

Tips 116: Window Center

Tips 117: Opens the specified Web page using IE

Tips 118: How to obtain the value of the data window computational domain!

Tips 119: grid-style DataWindow how to automatically wrap

1, Open the Datawindow In the Datawindow Painter;
2, In the column To be Set To automatically wrap, Double-click the mouse properties window bounce This column;
3, Select the Position tab, Select AutoSize Height checkbox;
4, Select the EDIT tab, And Uncheck Auto Horz Scroll checkbox;
5, click the OK button To Save your changes;
6, points Detail Band (ie written Detail gray Long belt), click the Right mouse button And Select properties … menu Item;
7, Select AutoSize Height checkbox;
8, click the OK button To Save your changes;
9, Save Datawindow. Height property still Write a column Expression: If (Len (Trim (file_name)) / 18 > 1, Ceiling (Len (Trim (file_name)) / 18) * 24,18) how many characters On the fold Line

Tips 120: 12 with a written statement about the date function

Tips 121: pb pure function analog Explorer window, click the mouse in action dynamic data sorting and display the sort arrow

Tips 122: pb in the first character of a string of characters to take a function

Tips 123: How to use WINSOCK control in the POWERBUILDER

Good Luck!

PassWords

About The Author

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments