The Code Window
Once you have been returned to your form, double click on the
OK button on your form. A new window will appear, and some VB code will be automatically
inserted. This is known as the Code Window. Let's take a look at the
code VB has inserted for you:
Private Sub cmdOK_Click()
End Sub
Although it might seem strange at first, it is actually quite
logical. First off, the words Sub and End Sub mean
that this is a Procedure. Procedures are blocks of code, that can be
executed (or run) by Visual Basic. The word Private
defines the group of procedures that can call it, but you don't need to worry
about that yet.
The most important part is cmdOK_Click(). If you
remember, cmdOK is the name of the button that you added to your form. The text
after the _ is known as the event. An event, just like in the outside
world is something that happens. In Visual Basic, 'event' occur all the time.
When the mouse is moved over the form, or when the user enters some text into
a textbox, all of these trigger events.
In this case, the event is Click, and occurs, not
surprisingly when cmdOK, the button, is clicked. Therefore, any code you enter
into this procedure will be run when the OK button is clicked.
Now take a look at the two drop-down boxes at the top of the window:
As you can see, the text in these boxes match what is written.
The box on the left lists all the controls that are on your form. If you click
it, you will see the names of the three controls that you added to the Form.
The right hand box lists all the events that can occur for this control. If
you click it, you will see a long list of possible events for the button; the
one that you are currently editing is displayed in bold (Click). If you select
another item in the list, Visual Basic will automatically add a new procedure.
Try this if you want, and then delete the text that VB added afterwards.