FUNCTIONS_AND_SUBROUTINES_final1
FUNCTIONS_AND_SUBROUTINES_final1
SUBROUTINES
FUNCTIONS
•What are functions?
• Code enclosed by a Function and an End Function.
• A series of Visual Basic statements enclosed by the
Function and the End Function.
• performs computation and analysis to return some
value.
• Functions return values. example, a function can
compute the area of the circle, which will return the
value (area)
SYNTAX OF A FUNCTION
• [accesibility]
• Function Function_name
• [parameters]
• [As] return_type]
statements
• End Function
EXPLAINING THE
SYNTAX
•[accesibility]- specifies which pieces of code can be accessed
from the code.[Lecture 6 on Events –Reserved Words] e.g Public,
Private etc.
• Name of the Function – should be a valid VB identifier beginning
with a letter or an underscore. eg.CubeVolume - see notes on
[rules for naming variables].
In our case the value in the variable first will get passed to
the first variable in our AddNumbers Sub; the value in the
variable second will get passed to the next variable we set
up in our AddNumbers Sub.
HOMEWORK
ACTIVITY
• Add a new button the form you created in the
previous section. Double click the button and add
the following code:
• Dim Number1 As Integer
• Number1 = 10
Call IncrementVariable(Number1)
• MessageBox.Show(Number1)