Writing Code in Visual Basic


A good programming habit is to add comments. A comment begins with a single quote. The Visual Basic compiler ignores everything after a single quote. Comments are a way for the programmer to leave notes for themselves. Add a comment with your name and an overview of what the program does. Add comments to tell what each procedure does. Comments are shown in green.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Public Class Form1
    'Programmer: Janet Joy
    'Change color of form with buttons
    Private Sub BtnRed_Click(sender As Object, e As EventArgs) Handles BtnRed.Click
        'change color to red
        Me.BackColor = Color.Red
        Me.Text = "You clicked red"
    End Sub

    Private Sub BtnBlue_Click(sender As Object, e As EventArgs) Handles BtnBlue.Click
        'change color to blue
        Me.BackColor = Color.Blue
        Me.Text = "You clicked blue"
    End Sub
End Class
CODE

NEXT: Selecting code from list