VISUAL BASIC 6.0
Function And Procedures

                          By Pragya Ratan Sagar
Functions
It is a separate procedure that can take arguments, perform a series of
statements and change the value of its argument
                             or
Functions are named blocks program code that perform a specific task
and return a result. The task can be as simple as adding two numbers
or as complex as launching a spacecraft

Syntax:
   Function FunctionName(argument list) As Datatype
        VB statements. . . .
   End Function

                                                                          1
The arguments to the function are declared as :
    1. By ref
        When passing by reference, the address of arguments are passed.
Example:
Public Function Sum(ByRef Number1 As Double, ByRef Number2 As
Double) As Double
         Sum = Number1 + Number2
End Function

2. By val
       When passing by value, copies of the arguments are passed.
Example:



                                                                          2
Procedures
Procedure is a block of statements which performs a particular task,
just that it does not return a result
Syntax:
[Private|Public] Sub ProcedureName(argument list)
  VB Statements. . . .
End Sub

Types of procedures:
1. General Procedure
   General procedure is one that we create for our own specific
   purpose.
2. Event Procedure
   Event procedure is a procedure associated with the event of an
                                                                        3
   object and are named in a way that indicates both event and object
   clearly.
Calling a Procedure
Procedure are called with or without the keyword call
Syntax:
….
Call procedurename()
….

Example:
Private Sub clearcontrols()
Text1.text = “ “
                                 General Procedure
Text2.text = “ “
End Sub

Private Sub cmdreset_click()
Call clearcontrols()             Event Procedure
End Sub                                                 4
Function And Procedures




                          By Pragya Ratan Sagar

VB Function and procedure

  • 1.
    VISUAL BASIC 6.0 FunctionAnd Procedures By Pragya Ratan Sagar
  • 2.
    Functions It is aseparate procedure that can take arguments, perform a series of statements and change the value of its argument or Functions are named blocks program code that perform a specific task and return a result. The task can be as simple as adding two numbers or as complex as launching a spacecraft Syntax: Function FunctionName(argument list) As Datatype VB statements. . . . End Function 1
  • 3.
    The arguments tothe function are declared as : 1. By ref When passing by reference, the address of arguments are passed. Example: Public Function Sum(ByRef Number1 As Double, ByRef Number2 As Double) As Double Sum = Number1 + Number2 End Function 2. By val When passing by value, copies of the arguments are passed. Example: 2
  • 4.
    Procedures Procedure is ablock of statements which performs a particular task, just that it does not return a result Syntax: [Private|Public] Sub ProcedureName(argument list) VB Statements. . . . End Sub Types of procedures: 1. General Procedure General procedure is one that we create for our own specific purpose. 2. Event Procedure Event procedure is a procedure associated with the event of an 3 object and are named in a way that indicates both event and object clearly.
  • 5.
    Calling a Procedure Procedureare called with or without the keyword call Syntax: …. Call procedurename() …. Example: Private Sub clearcontrols() Text1.text = “ “ General Procedure Text2.text = “ “ End Sub Private Sub cmdreset_click() Call clearcontrols() Event Procedure End Sub 4
  • 6.
    Function And Procedures By Pragya Ratan Sagar