All logic statements in your code must appear within a procedure, whether in a subroutine, a function, or a property. Although there are thousands of prewritten procedures for you to choose from in the .NET Framework libraries, you can also add your own.
Subroutines begin with a
Sub declaration statement and end with an
End Sub statement. All of your subroutine's logic appears in between these two mighty jaws.
01 Sub ShowIngredients(ByVal gender As Char) 02 Dim theMessage As String = "Unknown." 03 If (gender = "M"c) Then 04 theMessage = "Snips and snails and puppy dog tails." 05 ElseIf (gender = "F"c) Then 06 theMessage = "Sugar and spice and everything nice." 07 End If 08 MsgBox(theMessage) 09 End Sub
Line 01 shows the subroutine's declaration line in its simplest form; throughout the book, you will find that there are additional keywords that decorate procedure declarations to change their behavior. The statement begins with the
Sub keyword (for subroutine), followed by the name of the procedure,
The parentheses following this name contain the subroutine's parameters. Parameters allow another block of code that will use this procedure to pass data into the procedure, and optionally receive data back. You can include any number of parameters in the subroutine definition; simply separate them by commas. Each parameter specifies the name as it will be used in the procedure (
gender in the sample) and its data type (
Char). The arguments ...