Procedure: – A procedure is a self-content group of visual basic commands that can be accessed from a remote location within a visual basic program. Programming task can be simplified by breaking the program code into smaller module or component. These smaller chunks are called procedure. These are building blocks and useful for condensing repeated or shared task, such as free quaintly used calculation, text and control manipulation and data base operation.

The procedure then carries out same specific action. Information can be freely transferred between the calling location and the procedure itself. Thus, it is possible to transfer information to a procedure, process the information with in the procedure and then transfer a result back to the calling location.

A procedure is a named sequence of statement executed as a unit and it instruct the application how to perform a certain task. Code with in a module is organized in procedure. The procedure either belonging to a form module or standard module. The benefit of using procedures are –

  • (i) It can avoid repeating codes. If we have identical code in two or more event procedure, we may be able to write it just once in a procedure instead.
  • (ii) It makes the code more readable. An event procedure with many lines of code may be easier to understand if some of code is put into procedure.
  • (iii) It helps in debugging a program. Splitting the program up into. Smallest logical unit will make it easier to trace any error. In the program when it runs. This is called debugging a program.
  • (iv) It uses a procedure in other program. Suppose we had written same code that validated a data. We could use this procedure in any other program that used a similar data.
  • (v) All good programmer wants to pass parameters, where appropriate only by having procedure can be do this. Visual provide three different types of procedures. They are called –
    1. Sub procedure
    2. Function procedure
    3. Property procedure

Sub procedure: – A sub procedure is a block of a statement that carries out a well define task. The block of statements is placed with a pair of sub and end sub statement and can be invoked by its name. Syntax of the sub procedure is –

                                Sub <Procedure Name> (Arguments)
                                                Statements
                                End Sub

The procedure name must fallow the naming convention. Is addition, a procedure name cannot be identical to a constant or variable name with in the same module. The list of argument is optional. Arguments represent information that is transfer into the procedure from the calling statement. Each argument is written as variable declaration. Such as <Argument Name> as <Data Type>. The data type can be omitted it the argument is variant.

Function procedure: – A function procedure executes the task and reports back to the procedure from where it is called, returning a value. In other words, a function stores a value in a particular value and when it ends, value stored in automatically return to the calling procedure.

A function procedure is similar to a sub procedure, with one important difference such as a function is intended to return a single data item, just as a library function returns a single data item each function name, there for, represents a data item, and has a data type associated with it. Function can return either Boolean, integer, long, single, double, currency, data, string, variant or object data. By default, it is of variant type. Syntax of the function procedure is –

                Function <Procedure Name> (Argument) As <Data Type>
                                Statements
                                _ _ _ _ _
                                _ _ _ _ _
                                <Procedure Name> = <Expression>
                                _ _ _ _ _
                                _ _ _ _ _
                End Function

The list of argument is optional. Arguments represent information that is transferred into the procedure from the calling statement. Each argument is written as a variable declaration.

Property procedure: – Inside class module we define variables, which are properties of the class. Theoretically we could declare all variables as public show that all other project code set and retrieve value. However, this approach violates the rules of encapsulation that requires each object to be in charge of its own data. As a private variable, the value is available only to the procedures with in the class modules, the same way the module label variables are available only to procedures with in the form module.

When our program creates object from our class, we will need to assign values to the properties. Because the properties are private variable, we will use special property procedure to pass value to the class module and to return value from the class module. Property procedures are the code which runs when a property of an object get a new value or when value return. There are two property set using class module. These are actually property procedure. They are property get and property set. Both property procedure serves as a gateway to assign at retrieve property value to private member of the class module.

Advertisements