![]() |
.NET is a software framework that is designed and developed by Microsoft. The first version of the .Net framework was 1.0 which came in the year 2002. In other words, it is a virtual machine for compiling and executing programs written in different languages like C#, VB.Net, etc. Sub Procedures:A subprocedure is a group of VB.NET statements. It begins with a Sub keyword and ends with End Sub keywords. A subprocedure is also called a subroutine. It is used to execute a certain block of statements consists the body of the procedure. It is called explicitly by its name whenever it is required to perform a certain task. It can be called any number of times. The subprocedure returns control to the calling code after performing a task. Structure of Subprocedure:
Example: Module module1 Sub SubDivide(ByVal num1 As Integer, ByVal num2 As Integer) Dim res As Integer If (num2 <> 0) Then res = num1/num2 Console.WriteLine("Divide by Zero is possible") Else Console.WriteLine("Divide by Zero is undefined") End If End Sub Sub Main() Dim a As Integer Dim b As Integer Dim res As Integer Console.Write("Enter Number 1") a = Console.ReadLine() Console.Write("Enter Number 2") b = Console.ReadLine() SubDivide(a, b) Console.WriteLine(res) End Sub End Module Output: ![]()
Function Procedures:A function procedure is a group of VB.NET statements. It begins with a Function keyword and ends with an End Function keyword. It is generally used to perform a task and return a value back to the calling code. It may have multiple return points to the calling code. A part from return stamens, End Function, or Exit function also returns control to the calling procedure. Structure of Function Procedure:
Example: Module module1 Function FunctionDivide(ByVal num1 As Integer, ByVal num2 As Integer) As Integer Dim res As Integer If (num2 <> 0) Then res = num1/num2 return res Else Console.WriteLine("Divide by Zero is undefined") End If End Function Sub Main() Dim a As Integer Dim b As Integer Dim res As Integer Console.Write("Enter Number 1") a = Console.ReadLine() Console.Write("Enter Number 2") b = Console.ReadLine() res = FunctionDivide(a, b) Console.WriteLine(res) End Sub End Module Output: ![]()
Comparison between SubProcedure and Function:
|
Reffered: https://www.geeksforgeeks.org
Programming Language |
Related |
---|
![]() |
![]() |
![]() |
![]() |
|
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |