18. Subs

In this tutorial, we cover the Sub or Sub Procedure in Visual Basic .NET. Creating a sub is a way of storing lines of code and then executing the lines of code inside of the sub when it is called. This tutorial will show you how to store code for a message box in a sub and then call it when clicking a button.


Public Class Form1

    Sub givemessage()
        MessageBox.Show("I am cool for using subs")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call givemessage()
    End Sub

End Class