vb6.0 Lesson

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/jywlchuang/article/details/102656702

A collection (Collection)
Dim AS COL new new Collection
1, the method:
(1) COUNT: count the number of objects. The return value is a long integer, and is read only at design and runtime.
(2) add: add an element to the set
(3) remove: remove an element from a set
(4) item: Gets the specified element from the collection

2, a set of controls (controls collection)
Controls: is the collective name for all objects on the form. controls methods and collection methods, like: count, add, remove, item .
Such as:
(1) to dynamically create textbox controls:

dim text as textbox
set text=controls.add("vb.textbox","text")      '动态创建一个name为text的textbox
text.visable=true

(2) will show "VB" all the textbox controls on the form

dim i as object
for each  i   in me.controls
      if typename(i)="textbox"   then
         i.text="VB"
      end if 
next i

Second, during
the process: the function is a relatively independent program logic unit, i.e., a separate piece of code. VB program are generally composed of process.
Divided into: event procedure, a general procedure.
1, the event procedure: click, load, change and so on.
2, general procedure: The same section of the plurality of event processes program code to be used. It can be established separately for the event procedure or other procedure calls. Is divided into: sub-process (Sub procedure), the process function (function process) attributes and process (property procedure).
(1) sub process returns no value
(2) functiion procedure returns a value
(3) property set and the process may return forms, standard modules and module-based, object properties may be provided.
(A) event procedure: It is attached to the form and control the process. When an object in VB make a determination on the occurrence of an event during the event is automatically called with the name of the event. Such as the button's click event procedure.

Private sub command_click()
     label1.caption="hello the world !"
end sub

1, call the event procedure
(1) using the call statement
call <event procedure name> [(parameter list)]
, such as calling the command1 click event procedure.

  call command1_click

When using the call statement, the parameter list must be enclosed in brackets.
(2) direct use name
<event procedure name> [<parameter list>]
parameter list is not enclosed in parentheses.

2, sub-process (sub process)
sub-process may also be referred to as a sub process or a general procedure, is used to accomplish a specific task. Use sub process must first establish it, and then direct the course name or use the call statement to call.
(1) establish a sub-process
① entered directly in the code window
Syntax:
[Private] [Public] [the Static] Sub Sub procedure name (parameter list)
<statements>
[Exit Sub]
<statement>
End Sub

② using the "add process" dialog box: Tools → Add → open process "add process" dialog box → enter the sub-processes "name"

option explicit
'子过程的定义
'子过程带有两个参数
Private sub subcomputearea(lenth, thewidth)
     lblarea.caption=val(length)*val(thewidth)  '计算矩形的面积
end sub    

(2) call sub-process
① use the call:
call <subroutine> [(parameter list)]
, such as: call subcomputearea (txtlength, txtwidth)
using the call statement, the list of parameters must be placed in parentheses.
② direct the course name
subcomputearea txtlength, txtwidth

(3) call sub-process of other modules
① subroutine call Form
Form Form module all external calls directed modules must contain this procedure. If a subprocess contains mysub in the form1 form module, the following statement can be used to call.
call form1.mysub (parameter list)

② subroutine call a class module
similar to the subroutine call form. For example, a DemoClass instance of class1
Dim DemoClass new new AS class1
democlass.somesub
but is different from the form, in reference to an instance of a class, the class can not masterpiece qualifiers must declare an instance of the class object variable (in this examples are democlass) and reference it with the variable name.

③ call sub-process in a standard module
if the child process name is unique, it is not necessary to add the module name when calling. Whether it is in the module, or call in outside the module.
If two or more modules comprises sub-processes of the same name, then there is the module name must be defined. Call a public process will run within the process module within the same module. For example, for the sub-process called commonname module1 and modeule2, call the subroutine from module2 in commonname run commonname sub-processes of module2. Without commonname subprocess 1. At this point it is necessary to specify the module name, the statement is as follows:
module1.commonname (parameter list)
module2.commonname (parameter list)

(C) Function process
is different from the sub process is: function procedure can return a value to the calling program.
1, the process of establishing function
[Private] [Public] [Static ] function function name [(parameter list)] [AS type]
<statements>
[Exit function]
<statement>
End function
of As procedure return function clauses determine data type value . If the data type as clause is omitted, the function returns the value of the process variable size. Therefore, based on actual programming, using as clause.

2, the function calls the process
function procedure can also be called a user-defined function. So it is no different in VB calling internal functions, the return value of a function will soon assign a variable. The syntax is as follows:
variable name = function name (parameter list)
Note: If the function name, the function procedure returns a default value: the function returns the value 0, the function returns a zero-length string string, i.e., an empty string, variant The function returns empty. If you do not object referenced by the set assigned to the function name in the function returns the object reference of the process, the function returns the process nothing.

Different function is that processes and sub-processes: the process can return values by using the function name of the process, but only returns a value; sub-processes can not return value name of the procedure, but can return parameter values, and can return multiple values.
The same point: can modify any value passed to the variable thereof.
Special Note: If you are under development, the brackets no parameters, then VB will not pass any parameters, however, if you use the argument when calling the procedure, an error occurs.

Guess you like

Origin blog.csdn.net/jywlchuang/article/details/102656702