Chinese people's own development language HB ++ <statement introduction>

zhaozj2021-02-08  242

These are basic development language statements, HB has made a lot of support for face-to-face, in this regard, more excellent in object-oriented support than VB.NET. Here, HB is introduced here, and you can correct and help

3.2 statement

Sequential statement

a) assignment statement

LET basic type assignment statement

[Let] variable name | class member variable name = expression

SET non-basic type assignment statement

SET variable name | class member variable name = expression

SET variable name | class member variable name = new non-basic type name [(parameter table when constructed)]

b) call function

CALL call function statement

[Call] Function Name | Class Member Function Name (Parameter Table)

Even if the function has a return value, the return value will be automatically lost after using the CALL statement. If returned is a class instance, HB will automatically release class instance space.

2. Conditional statement

a) IF statement if statement standard format: IF logical expression THEN [ELSE IF logical expression THEN] [ELSE] end if b) SELECT statement SELECT statement Standard format: SELECT Arithmetic Expression Case Logic Expression [Case Else] End SELECT Note: The first logical operator of the logical expression here does not require the left algorithm. For example: DIM A As Long

A = 10 SELECT A 3 Case <2 case> 2 and a 3 <10 case> 10 and A 3 <100 CaseElse End SELECT

3. Cycling statement

a) for loop statement

standard format:

FOR cycle variable = initial value TO termination value [step step length]

NEXT cycle variable

The loop variable can only be a separate variable, and cannot be a class of members attributes or functions. The default value of the step size is equal to 1.

The cycle variable of the next statement must be the same as the loop variable in the for statement.

EXIT FOR statement will jump out of the loop

b) FORSET collection dedicated loop statement

FORSET collection variable

Nextset

Collective variables can only be an instance variable of a collection class. Its initial value is the first element of the collection. This loop will automatically circulate the last element of the set of the first element. The contents of the set variable operation element are used directly in the cyclic body.

EXIT FOR statement will jump out of the loop

c) do while ... loop When the condition is a true cycle statement

Do WHILE logic expressions

Loop

The condition is first circulating, when the external entry cycle, the conditions are not established, and the loop will jump.

The EXIT DO statement will jump out of the loop

d) DO Until ... loop When the condition is a true jumping loop statement

DO Until logical expression

Loop

The conditions are previously circulated, and when the outside enters the cycle, the conditions are established, and the loop will be skipped.

The EXIT DO statement will jump out of the loop

e) DO ... LOOP while judgment When the condition is a true cycle statement

DO

Loop While logical expression

The condition is followed by the cycle, when the outside enters the cycle, at least the time is cycled, and then determine whether the conditions are established, if it is established, the loop will jump out.

The EXIT DO statement will jump out of the loop

f) DO ... LOOP Until judgment When the condition is a true jump circulating statement

DO LOOP UNTIL logical expression conditions After the loop, when the external enters the loop, it will cycle it again, and then determine whether the condition is established. If it is not established, the loop will jump out. The EXIT DO statement will jump out of the loop

4. Define statements

a) Function function definition statement standard format: [Virtual] [public | private] Function function name ([[Byval | Byref] parameter name AS type name] [, [BYVAL | BYREF] [optional] parameter name AS type name [= Constant expression]] ...) AS type END FUNCTION function name: must be a valid letter: 26 cases of English letters, 10 numbers, underscore, all Chinese, the first letter must be English letters or Chinese, underscore; parameter name: same variable name; type name: basic data type, non-basic data type (object class), class template type; [Virtual]: virtual function definition, only in the member function of the class; [Public | Private]: Optional, public private instructions; [Byval | Byref]: Optional, parameter values ​​or press address. The default is based on the address transmission byref; [optional]: Optional, indicating that this parameter can write, ie, optional parameters. Optional parameters can give it to a default, the method is to follow one equivalent and constant calculation after it is defined. [= Constant expression]: Optional, when the arguments of the previously defined parameters are optional definitions. Variables cannot be used in constant expressions. END FUNCITON: End Function Definition

b) Class class custom statement

Standard format: Class Custom Type Name [From Existing Object Type Name] End Class Customized Type Name The alphabet of the same variable name, the custom type name cannot be the same as the existing type name. This type will be an object class. [From existing object type name]: from inherited statement, the custom type is required to inherit from existing object types. Type definition must be placed inside the module definition

c) MODULE module definition statement

Standard format: Module Module Name End Module The following will be able to define the following: Custom object type, global variable, global function, local variable within the module, local function within the module. The window category inside the module cannot be defined, and the window class is independent and all definitions. The content defined by the module must be in the same file. The content defined by the module is a global.

d) FORM window definition statement

Standard Format: Form Forms End Form HB , the Form statement defined window class will automatically create a window instance before compiling, and create a global static variable: window class. All content defined in Form ... End Form will be a member of this window or method or method or event. The method of inserting the control in the window is simple, as described below: (Since the visual programming section is not developed, the following method can be used) FORM window classes PUBLIC WITHEVENT button As Tbutton Public Withematic TreeView AS TTREEVIEW PUBLIC WITHEVENT EDIT AS TTEXT PUBLIC WITHEVENT In the above example, a button will be automatically inserted in the window, the tree, edit box, and toolbar will be automatically inserted in the window. When there is no positioning, if you want to locate, continue writing the constructor of the window class, locate each control in the constructor. The positioning method can be assigned to LEFT, TOP, WIDTH, HEIGHT, or the specified align mode. The window will only be released automatically when the program is ended. If you want to force the release to delete, you will be empty. You can: SET window = NULL Other object class forced release deletion. e) TypeDef type alias definition statement

Standard format: Typedef existing type name type alias Alias ​​You can be any HB type (including class template). The method of use of type alias is the same as the type name, although it is not a new type, but is identical to the type it points to.

f) Struct structure type definition statement

Standard format: Struct Structure of the Struct Structure, from HB , in HB , the definition of struct and classes is almost exactly the same, and can be used in one way.

g) DIM variable definition statement

Standard format: DIM variable name [(array size)] AS [new] type name [] [, variable name AS [new] type name [] ...] Variable name: Dynamic Variable name; [(array size)]: Optional, defined array; type name: HB all type name; []: Optional, if the type is a class template, the type parameter table here will be this Class parameters required for class templates. The parameter can be ten.

h) static static variable definition statement

Standard format: static variable name [(array size)] AS [new] type name [] [, variable name AS [new] type [] ...] Variable name: static Variable Name Other DIM Definition Statement Description.

i) PUBLIC public variable definition statement

Standard format: public [static] variable name [(array size)] AS [new] type name [] [, variable name AS [new] type name [] ... Name: Public Variable Name Using Static Description Variables are public static variables, and the default for unused is dynamic scalar. Other DIM definition statement descriptions.

j) private variable definition statement standard format: private [static] variable name [(array size)] AS [new] type name [] [, Variable Name AS [New] Type Name [] ...] Variable Name: Private Variable Name Using static Description Variable is a private static variable, and the default is the dynamic scalar. Other DIM definition statement descriptions. Note: In variable definitions, if it is a variable of the object type, you can use New to create class instances, but the NEW cannot be used in class properties definitions. If NEW is not used in the variable definition, you can create the object class in the execution program. For example: DIM A as TFORM SET A = New TFORM

5. Event definition statement

a) EVENT event definition statement

Standard format: EVENT event function name ([[Byval | Byref] parameter name AS type name] [, [Byval | Byref] [OPTIONAL] parameter name AS type name [= constant expression]] ...) EVENT event definition statement Define the function name and parameter form of the event function. The EVENT statement must be used in class definitions. When defining this event function of the class instance, the event function name defines the format as follows: class instance variable name _ event function name, for example: Module Example Module Class Example Pulic Event over (Byval x as long (byval y as long) PUBLIC OLDX AS Long, Oldy As Long Function Line (BYVAL X As Long, BYVAL Y AS LONG) RAISEEVENT OVER (X, Y) window class. LINE (Oldx, Oldy, X, Y) End function 'method of pre-defining event process functions:' With pre-defined event functions, this class instance automatically owns the processing of this event function after the construct is created. Function _over (byval x ask) IF x> 0 and x <100 and y> 0 and y <150 THEN MSGBOX ("Enter this area is valid!") End if end function end class end module form window Class from TFORM PUNLIC WITHEVENT B AS TBUTTON PUNLIC C AS Example Class PUBLIC WITHEVENT D AS Example Class Function B_Click () End Function Function C_OVER (BYVAL X As Long (BYVAL Y) IF X> 100 and x <200 and Y> 150 AND Y <300 THEN MSGBOX ("You can't enter this area!") End if end function end form

b) raiseevent excitation event statement

Standard Format: RaiseEvent Event Function Name (Parameter Table) Examples in Event. c) WitHevent Defines Object class instance variables with events

The WitHevent statement is used in the defined variable, which indicates that the defined variable will automatically obtain class instances when constructing. If it is a control class instance, it will be inserted into the window class. WitHevent's variable must be defined as an object type, if it is the basic data type, HB will report an error. An example of explaining in Event.

6. Error handling statement

a) OneRror turns on the error handling statement

Standard format: OneRROR OneRror means that if there is an error since this row, it will be automatically transferred to DoError.

b) DoError error handling statement

Standard format: doerror [Function Name (Parameter Table)] Doerror If there is no function after the back, when an error is in the code between OneRror to DoError, the DOERROR statement will be automatically executed to the program code between CloseError. This function will be called automatically if the function is used later.

c) CloseError turn off error handling statement

Standard format: CloseError turns off error handling. After the shutdown, the error is performed, and HB does not stimulate the Doerror processing error and report the system error.

d) Resume Restore the execution statement

Standard format: Resume [Next | Exit] Resume: After the error is handled, use this statement to continue to perform the resume next: After the error is handled, use this statement to return to the error EXIT: After the error is handled, use this statement to exit the current function. Note: The error handling mechanism for HB allows nested. When an error, HB will automatically find the most recent error handled Doerror. Such examples: Function ABC (A As Long, B As Long) DIM C As Long OnError A = 10 B = 0 c = A / B OneRror A = 5 C = A / B DOERROR MSGBOX (a) Resume Next CloseError A = 20 c = a / b doerror msgbox (a) resume next clsoeerror end function running results: "10", the second prompt "5", the third prompt "20".

7. Property function definition

a) Property GET read operation function definition statement

Standard format: Property get attribute function name () AS type name [<>] End Property

b) Property Let Basic Data Type Write Operation Function Definition Statement

Standard format: Property Let Attribute Function Name ([Byval | Byref] Parameter AS Basic Data Type Name [<>]) End Property

c) Property SET Object Type Write Operation Function Definition Statement

Standard Format: Property SET Property Function Name ([Byval | Byref] Parameter AS Object Type Name [<>]) End Property Note: Property GET and Property Let Pairing or Property Get and Property Set Pair, Type of name must be the same D) read-only properties or only write properties

Read-only properties: Just use the Property GET defined attribute read function. Only write properties: just use the Property LET or the Property Set Define the attribute write function. Examples: Module example Module Class Examples Class Private FData as Long Property Get Data () as Long Data = FData End Property Property Let Data (ByVal Value as Long) FData = Value End Property End Class Function Dispaly () dim d as New example class D.Data = 10 msgbox (d.data) End function end module

转载请注明原文地址:https://www.9cbs.com/read-2122.html

New Post(0)