Code eg 1: Function.
Public Function CalculateScore() as Integer
' Declare variables
Dim TotalDamage As Integer = 555
Dim TotalAgility As Integer = 6
' Create the expression
Dim TotalPoints As Integer = TotalDamage * TotalAgility
Return TotalPoints
End Function
' Declare variables
Dim TotalDamage As Integer = 555
Dim TotalAgility As Integer = 6
' Create the expression
Dim TotalPoints As Integer = TotalDamage * TotalAgility
Return TotalPoints
End Function
A function returns a value to the calling procedure. In the above case, the function will return the value of the variable called TotalPoints. The As Integer part of the function header, indicate that the function will return a value that is of the Integer type.
Code eg 2: Function.
Public Function getFirstName() as String
Return strFirstName
End Function
Return strFirstName
End Function
This new example shows a function that will return a String value.
No comments:
Post a Comment