Writing Visual Basic Coding (Tutorial 1 Lesson B Visual Basic Book)

Actions such as clicking, double-clicking, and scrolling are called EVENTS.

You use the Code Editor Window to tell and object (like a button) how to respond to an EVENT within the Code Window in what’s called an EVENT PROCEDURE.
*You can jump to the Code Editor Window by right-clicking anywhere on the form (except the Title Bar) and then select View Code from the context menu.

** You can also click View on the menu bar, and then click Code; or you can press the F7 key on
your keyboard.

Above you can see that the code begins with Public Class frmCopyright and ends with End Class this is known as a Class Definition. A Class Definition is simply a block of code that specifies (or defines) the attributes and behaviors of an object.

The above image is the Code Window for the Mech Form. Notice the Inherits System.Windows.Forms.Form instruction included in the Mech Form class definition. The Mech Form (the derived class) inherits the attributes and behaviors for the Form class (the Base Class), which is provided by Visual Basic 2013 and defined in the Systems.Windows.Forms namespace. In other words, rather than you having to write all the code necessary to create a Windows form object, Visual Basic provides the basic code in the Form class.

The Code Editor Window contains a Class Name list box and a Method Name list box. The Class Name list box list the names of the objects included in the user interface. The Method Name list box lists the events to which the selected object is capable of responding. You use the Class Name and Method Name list boxes to select the object and event that you want to code.

To help you follow the rules of the Visual Basic programming language, called syntax, the Code editor provides you with a code template for every event procedure. The first line in the code template is the Procedure header and the last line is called the procedure footer.

In the Procedure header:
Private Sub cmdExit_Click(sender As Object, e As EventArgs)

Sub – is an abbreviation for the term sub procedure, which in programming terminology refers to a block of code that performs a specific task.

Private – indicates that the procedure can only be used within the class in which it is defined, in this case only within the frmCopyright class.

cmdExit – name of the object

_ - used as a separator between the object name and the event name

Click – name of the event.

(sender As Object, e As EventArgs) – The items within the parenthesis are called Parameters and represent information that ais passed to the procedure when it is invoked (executed).

To end an application, you invoke the Me.Close() method. A method is simply a predefined Visual Basic procedure that you can call (invoke) whe4n needed. PLEASE NOTE: The parenthesis are required when calling any Visual Basic method, however depending on the method the parenthesis may or may not be empty.

Complete Page 69 Exercise #1 as a quiz for what you have completed so far.

Changes for Exercise #1: MechForm should be frmMech, CompanyLabel should be lblCompany, ExitButton should be cmdExit, Change 240 Pixels to 230 Pixels in letter p, and skip step r. Show the completed form to Mr. O’Hara