[PB] PB programming

Source: Internet
Author: User
Chapter 1 General Usage

1. Start of the program and open event of the application.

Exit the program routine: (halt is used to exit the function)

Int surequit

Surequit = 2

Surequit = MessageBox ("Exit System", "confirm that data is saved before exiting", question !, Okcancel !, 2)

If surequit = 1 then halt

2. Effective scope of variable definition:

◎ Declare-globe global variable, effective throughout the program

◎ Declare-instance local variable, which can be valid in an object (such as a form or app)

◎ Variables defined in the module can be valid in the current Module

Definition: (PB is case-insensitive)

Constant string ls_homecity = "Boston" // constant

Int A // integer

Char C // character type

Boolean B // Boolean

String a // String type

String a [1000] // an array of 1000, 0 ~ 1000

String a [3 to 30] // The array element is 3 to 30. The first element is a [3], and the last element is a [30].

String a [100, 3to 30] // two-dimensional array, one-dimensional 0 ~ 100, two-dimensional: 3 to 30

String a [] // a variable-length array. Memory is automatically allocated when values are assigned (for example, a [30] = 333.

Obtain the upper bound UPPERBOUND and lower bound LOWERBOUND.

Operation:

A = "aaaa" + "vvvbb" + B + c

String (B) // convert B to string type

Integer ("333333333333") // converts a "333333333333" string to a number of 333333333333

A = a + B * c ^ d/e \ f % g // Note: spaces are required before and after the minus sign to avoid bugs in versions earlier than PB7.0.

3. Function Definition:

The first row is the return type and function name, the second row is the variable type and variable name, And the tab key is used to add parameters.

Return is the return of the function. Similarly, if Return is the same as the C language, the function stops running.

4. Open a window

Open (window name)

Openwithparm (window name, parameter, parent window <only valid for child forms and pop-up forms>)

5. Open the child form in the MDI form

Open opensheet (child form, parent form name, 1, layered !)

Open opensheet (child form, parent form name, 1, Original !)

If you want to write it in the form-level function of the parent form, you can use opensheet (child form, this, 1, Original !)

The third parameter indicates the position of the new form in the parent form menu.

6. Basic Properties of controls

Control name. x // x coordinate

Control name. y // Y coordinate

Control name. width // width

Control name. height // height ...... (For other information, see the attribute window in the editor)

7. Adjust the form Mode

This. windowstate = maximized!

Form. windowstate = maximized! Maximize forms (for other information, see the attribute window in the editor)

8. INI File Reading and Writing

[Example] The INI file named "MNR. ini" (path in the directory where the program is located) has the following data:

[Action]

Preload = Yes

You can use the following statement to read data:

A = profilestring ("MNR. ini", "action", "preload", "AAA ")

A is a variable and "AAA" is the default data if no data item exists.

You can use the following statement to write data (the write value is yes ):

Setprofilestring ("MNR. ini", "action", "preload", "yes ")

9. variables used in the entire program

You can define a structure first, and then define the structure type variable in globe declare to facilitate management.

10. Main syntax units

A. Condition judgment

If how then

How to do

How does else if then

How to do

End if

Choose case variable

Case is <3

...

Case 4 to 7

...

Case else

...

End choose

B. loop to a greater than 5

DO

A = a + 1

Loop until a> 5

Do while a <= 5

A = A + 1

LOOP

DO

A = a + 1

Loop until a> 5

Do until a> 5

A = A + 1

LOOP

Exit the loop and continue the next loop.

11. Message Box

MessageBox (title, Information) other help, query index MessageBox

12. Get the current time now ()

Sle_begintime.text = string (now (), "yyyy-mm-dd 10:00:00 ")

For example, the output is 17:22:21.

13. Apply the list box

DDLB_BSC.RESET () // clear the contents of the list box

I = 1

Do while I <= UpperBound (WINBSC)

If winbsc [I] = "" THEN EXIT;

DDLB_BSC.ADDITEM (WINBSC [I]) add content items to the list box

I = I + 1

LOOP

Chapter 2 application database

1. Use of the datawindow Control

Create a datawindow object dw_hwtj, add a datawindow control dw_rep to the form, and set the dataobject attribute of datawindow to dw_hwtj.

A) The row selection function I wrote is used in the click Event of the datawindow control.

If row = 0 then return

If nowrow <> row and nowrow> = 0 then

THIS. SELECTROW (nowROW, false)

End if

THIS. SELECTROW (ROW, TRUE)

Nowrow = row

B) the sorting function I wrote is used in the double-click event of the datawindow control.

IF dwo. Type = "column" THEN

Ls_columnname = dwo. Name

END IF

If nowstate = 'A' then

THIS. SETSORT (ls_columnname + "D ")

NOWSTATE = 'D'

ELSE

THIS. SETSORT (ls_columnname + "")

NOWSTATE = 'A'

END IF

THIS. SORT ()

(Effect: Double-click a column to sort the column forward and reverse)

C) specified sorting

Dw_rep.setsort ("bscmc a, xqh a, xqmc ")

Dw_rep.sort ()

(Sort by BSCMC, XQH, and xqmc)

D) Save It To The xls file

Dw_rep.saveas ('', Excel5 !, True)

E) read/write:

Write w_netrep_cell.dw_rep.object.tchpzzs [I] =

Read a = w_netrep_cell.dw_rep.object.tchpzzs [I]

2. Establish a connection with the database

1) Definition

Transaction localdb

2) settings

Mytrans. DBMS = ""

Mytrans. Database = "SDA"

Mytrans. logpass = "def"

Mytrans. servername = "DBO"

Mytrans. logid = "ABC"

Mytrans. dbparm = ""

Mytrans. Lock = ""

Mytrans. userid = "ABC"

Mytrans. autocommit = true

3) Connection

Connect to connect using localdb;

Disconnect disconnect using localdb;

4) query multiple rows of data from the database: (the query statement is fixed)

Connect using localdb; // connect

If localdb. SQLCODE <0 then

Messagebox ("failed to connect to the local database...", localdb. sqlerrtext)

Return 1

End if

DECLARE MY_CURSOR cursor for // defines the CURSOR

Select bsc from bsc order by bsc using localdb; // execute the query

I = 1;

OPEN MY_CURSOR; // OPEN the cursor

Do while not localdb. sqlcode = 100 // until the end

If I> upperbound (winbsc) Then exit

Fetch my_cursor into: winbsc [I]; // extract data items

I = I + 1

Loop

Close my_cursor; // close the cursor

Disconnect using localdb; // disconnect

5) query a row of data from the database: (the query statement is solidified) in the help routine, ":" adding a string is the variable whose index is the string.

Select employee. emp_lname, employee. emp_fname

Into: emp_lname,: emp_fname

From employee

Where employee. emp_nbr =: emp_num

Using emp_tran;

6) used in operations such as data update, deletion, addition, and table creation:

Check dynamic SQL format 1 statement ...... Dynamic SQL format 4 Statement, which is clearly described (see sample)

Execute a statement directly:

Execute immediate sqlstatement {using transactionobject };

Help is very clear, so I won't talk about it more here.

7) non-fixed query statement: This is very important for improving software flexibility, but it is very simple. Only one sample in help is attached:

Declare my_cursor Dynamic Cursor for sqlsa

String sql1, sql2

Sql1 = "SELECT emp_id FROM department WHERE salary> 90000"

Sql2 = "SELECT emp_id FROM department & // This is the branch Connection Symbol, followed by a space & Symbol

WHERE salary> 20000"

IF deptId = 200 then

Prepare sqlsa from: sql1 using sqlca;

ELSE

Prepare sqlsa from: sql2 using sqlca;

END IF

Open dynamic my_cursor;

Summary:

There is not much content, but the main things are all here. Other things should be understood in practice. This knowledge is sufficient for the development of the start-up and standard MIS systems. The help of SQL statements is sufficient. I will not go into details too much.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.