[VB learning] 5: Process and functions

xiaoxiao2021-03-06  40

Sub-process (SUB) definition

Event process

Form event process

Private Sub Form_ Event Name ([Parameter List])

[Local variables and constant statements]

Statement block

End Sub

Description:

(1) Form event process is composed of form_ event name, multi-document form with MDIFORM_ event name.

(2) Each form event process is prior to a private prefix, indicating that the event process cannot be called outside its own form module.

(3) The event process has a parameter, which is completely determined by the specific events provided by VB, and the user cannot add it casually.

Control event process

Private sub control name _ event name ([parameter list])

[Local variables and constant statements]

Statement block

End Sub

Description: The name of the control must match a control in the form, otherwise VB will consider it is a general process.

General process

[Private | Public] [Static] SUB Process Name ([Parameter List])

[Local variables and constant declarations] 'Declaration with DIM or STATIC

Statement block

[EXIT SUB]

Statement block

End Sub

Description:

(1) When default [private | public], the system defaults to public.

(2) static representation of local variables in the process of "static" variables.

(3) The naming rules of the process name are the same as the variable naming rules. In the same module, the same symbol name must be used as the SUB process name and used as the function name.

(4) The parameters in the parameter list are called a formal parameter, which can be a variable name or an array name, which can only be a simple variable, cannot be a constant, array element, expression; if there is multiple parameters, each parameter is used Command separated, no specific value. The process of VB can have no parameters, but a pair of parentheses cannot be omitted. The process without parameters is called no array.

Conversion format is: [BYVAL] variable name [()] [AS data type]

Description:

(1) Variable Name [()]: Variable name is a legal VB variable name or array name, hanging to numbers indicate variables, and there are brackets represent arrays.

(2) Byval: Indicates that the subsequent parameter is the value transfer parameter (pass value parameter passed by value), if the default or use byref, the parameter is indicated by the address (in-service parameters) or "reference" (Passed by reference).

(3) AS data type: The default indicates that the parameter is a variable variable, and if the type of parameter is declared as String, it can only be unregulated. When the process is called, the corresponding real parameter can be a set of strings or strings of a string, and if the shape is an array, there is no limit.

Sub-process (SUB) call

(1) Call the SUB process with a call statement: CALL process name (real parameter table).

(2) Use the process name as a statement: Process Name [Real parametric 1 [, Real Parts 2 ...]].

Definition of function (function) process

[Private | Public] [Static] Function function name ([Parameter list]) [AS Data Type] [Local Variable and Constant Declaration] 'Declaration with DIM or Static

[State block]

[Function name = expression]

[Exit function]

Statement block

[Function name = expression]

END FUNCTION

Description:

(1) The named rule of the function name is the same as the variable naming rules; the function process must return a value by the function name.

(2) If the function is not assigned to the function name, the default value of the corresponding type is returned, the numerical type returns 0, and the character type returns an empty string.

(3) The SUB process or the function process cannot be defined during the function process.

Call of function (function) process

(1) Call the process in the form: from the external call of the form module, the name of the form must be used as a call prefix. Such as: Call Form1.examSub ([Real Mesel])

(2) Call the process in the standard module: If in the application, the process name is unique, you do not have to add the module name when calling. If you have the same name, you may not add the module name when calling in the same module, and you must add a module name when calling in other modules.

(3) The process in the class module: When the publication of the class module is called, the variable modification process to which the class is required to be used, that is, the instance to be declared as an object variable, and use this variable as a process name prefix modification Words, not directly used as a prefix modifier. Such as: In the class module class1, the variable democlass is an instance of class class1, the method of calling Clssub is:

Dim Democlass As new class1

Call Democlass.clasub

Parameter transmission (1)

Press value transmission parameters (definition, when it is defined): When passing the parameter (Passed By Value), it is to copy the value of the real parameters to the temporary storage unit. If the value is changed during the calling process, no Will affect the real-argument variable itself, that is, the value before the debuminable variable is maintained.

(2) Press the address delivery parameter (there is no modified word or keyword byref): When passing the parameters, transmit the address of the actor to the called process, the metall parameter and the actual parameters, the same address. During the called process, the value of the parameter is changed, and the value of the corresponding arguments is also changed. If the argument is a constant or expression, VB will be processed by "transmission value" mode.

(3) Array parameters: VB allows array as a formal parameter in a shape parameter group name () [AS data type]

The shape parameter group can only pass the parameters by address, and the corresponding field must also be an array, and the data type is the same. When the call is called, the array name to be passed is placed in the real parameter table, and the array name is not with parentheses. You cannot use a DIM statement in the process to declare the array group, otherwise the "duplicate declaration" is generated. However, when using a dynamic array, you can use the RedIM statement to change the dimension of the array, redefine the size of the array.

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

New Post(0)