How Many Different Types Of Procedures Are There In VB?

2

2 Answers

raaga Profile
raaga answered
There are four types of procedures in VB.
1. Sub procedures
2. Function Procedures
3. Visual Basic Procedures
4. Event based procedures

Visual Basic procedures are the built in procedures provided by the language. These procedures provide the most commonly used functionality. Built in procedures work fast then the equivalent procedures written by the VB programmers. It's a good practice to know and use the built in procedures instead of writing some new version.

Event based procedures are the procedures that are invoked when some event is triggered like 'mouse clicked' or 'key pressed' etc. Some code is written under the header that the programmer wants to be executed whenever the event triggers.

Sub procedures are the procedures that are written by the programmer to perform some specific function. They can be created by the IDE as well as through code. Add procedure dialog is used for this purpose. In the code view click 'Add Procedure' and then select the type of procedure as sub and then choose or the access modifier you need. 'Private' limits the access to the function to the form on which it is defined while 'Public' identifier makes the function available for other forms also. Mention the name of procedure in the name text box and click OK. You will see the following code in your code window.

Private Sub ProcedureName ()
End Sub
You have to write the code between Sub and 'End Sub' that you want. You can also write this code directly in the code window instead of using the dialog box. Any arguments that you want to pass to the procedure are to be mentioned between the parentheses.
Functions procedures are also created the same way the only difference between sub procedures and function procedures is that functions return some values whereas sub procedures do not. Normally functions are used for calculating purposes and to return the result of the calculation. For this reason the syntax also varies now you have to mention the return data type in the function header. The syntax will be as follows
Private FunctionName(Argument list) as ReturnType
End Fuction
Anonymous Profile
Anonymous answered
There are two kinds of procedures in VB, one is Sub procedure and other is Function procedure.All statements are defined between Sub and End Sub statements. It does not return any value and if arguments are passed by calling procedure then it can take it.
Example 1:
Sub hello()
  statements ......
End Sub
If it take arguments then arguments are written as given below.
Sub hello(argument 1, argument 2)
  statements ......
End Sub   
Similarly, In a Function procedure all statements are defined between Function and End Function statements. A function procedure can return a value.  Just like Sub Procedure a Function procedure if arguments are passed by calling procedure then it can take it.
Example 2:
Function Hello()
  statements...
  Hello= any value
End function
If it take arguments then arguments are written as given below.
Function Hello(arg1,arg2)
  statements...
Hello= any value
  End function

Basically, procedures are used for increasing the performance of a program. Procedures are very important in VB and I can say that it is not possible to write an application without using procedures. Main advantage of procedures is that you write the code for just one time and you can use it several times. Procedures divide a program into smaller parts so it is easy to read it and it also helps in debugging.

Answer Question

Anonymous