This Visual Basic Tutorial is all about Subs.
In Visual Basic, a Sub procedure is a series of statements composed by the Sub and End Sub statements. It performs a task that returns control to the calling code, but it does not return any value. it is also used to declare the name, parameter and the body of a sub procedure.


This is the syntax in declaring parameter in the parameter list:

  1. [Optional] [ByVal | ByRef] [ParamArray] parametername As datatype


You can also visit this site for the advance tutorial in declaring parameter list. Click Here


This is syntax in performing a Sub statement:

  1. [Modifiers] Sub SubName [(ParameterList)]
  3. Statements.....
  5. End Sub


  1. Public Sub cArea(ByVal len As Double, ByVal wid As Double)
  2. ' Declare a variable.
  3. Dim area As Double
  4. If len = 0 Or wid = 0 Then
  5. ' If the argument = 0 then the Sub will exit immediately.
  6. Exit Sub
  7. End If
  8. 'It calculate area of rectangle.
  9. area = len * wid
  10. ' Print the area to the message Box.
  11. MsgBox(area)
  12. End Sub



Readers might read also:


Facebook Comments


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.