Procedures in Visual Basic

Writing a function is similar to writing a procedure. Procedures perform an action, but functions return an answer.

Start a new application and name it Hello. We are going to write the "Hello World" program, but using a function. Write the code as shown below:

'Programmer: Janet Joy
'Say Hello World using a function
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = getGreeting()
    End Sub

    Public Function getGreeting() As String
        Return "Hello World"
    End Function

End Class
Notice that the function header (the first line) ends with the type of value the function will return. The last statement in the body of the function is to return a value of that same type.

NEXT: Passing Arguments