Wyo VB - Ch. 2 Notes
Objective #1: Recognize the components of the Visual Basic programming
environment.
- The form window is your basic environment on which you
place objects that will be seen by the user.
- The Solution Explorer window shows the filenames of all
of the form (.vb) files that are contained in your current
project.
- The Properties window allows you to set most any property
of the object which is currently selected (i.e. highlighted) in the form
window.
- The Toolbox usually appears along the left edge of the
screen. It contains the tools that you use to place controls on a form.
You
can double click a tool to cause a control to appear on the current form.
You can also pass your mouse over each tool to see the name of the tool appear
in a pop-up window.
- The main Visual Basic window holds the menu bar (at the very top)
and the Toolbar (just under the menu bar).
- The Help menu is a very useful and often overlooked repository
of information. Use the online Help to learn about Visual Basic!
Objective #2: Identify objects, properties, and methods and explain
how they are different.
- Objects are generally any thing that you introduce within
a VB project. Examples of objects include forms and controls. Forms are
the
building blocks of your programs. A form is a window on
which you place other objects. Sometimes a form can take the form of a dialog
box which you are
accustomed to seeing in almost every Windows program. Controls are the things
that you place on top of forms. Controls include text boxes, command buttons,
and labels.
In the statement,
lblHello.Text = "Hello World"
lblHello is the name of an object. Specifically, it is a label.
- Properties are associated with objects. Any single object
has numerous properties that affect the way it is displayed and the way that
it interacts with the user and other objects. Referring to properties is tricky.
You must first include the name of the object, followed by a period, and then
the name of the property.
In the statement
lblHello.Text = "Hello World"
Text is the name of a property. It is a property of the label named lblHello.
The value of the property is being set to the string value "Hello World"
in this statement.
- Methods are actions that a programmer can use with objects.
For example, printing an object such as a form is a method of that form.
In the statement
?????
??? is the name of a method. It is a method that works with ???? objects.
This statement causes ????
Objective #3: Write, run, save, print, and modify a Visual Basic project.
- Type the code, which you have been required to memorize for this class,
into the code window of a blank form that must be named frmHello.vb
- Click the Run tool on the toolbar in order to execute the project.
- Click the Stop tool on the toolbar to stop the execution.
- Choose the Print menu option "Print Code".
- Change the Hello World phrase to something else and execute the program
again to see the change.
Objective #4: Describe the various files that make up a Visual Basic
project.
- Visual Basic programs can be called projects. VB is a more complicated programming
environment than older versions of Basic. The project consists of the following
files:
- A .vbp file which is the project file. You rarely would
have to edit this file but you must be aware of its existence and placement.
- One or more .frm files which each refer to the form
windows that the user will see during program execution. This file contains
references to the objects and their properties that are located on the
particular form. A form file is really called a form module in VB.
- More advanced programs will also include .bas files.
These files are called standard code modules and contain external procedures
that can be used by any form within the project.
- Even more advanced programs may include .ocx files
which contain custom controls. Usually you will be able
to write a program that only requires the standard control set which is
included with your version of VB. But you can purchase sophisticated controls
from third-party developers and use them within your project.
- A .vbw file is saved for each VB project that you create.
Visual Basic holds information necessary to execute the program here.
- VERY IMPORTANT:
You must always create a new folder to store all of a projects associated
files before you begin the project. Be sure to create the project within this
folder so that you will be able to find all of the necessary, associated files
in the future. After creating a VB project, you must be very careful if you
have to move a form module or other file because this may render your program
unexecutable. Also, do not rename files after creating them unless you know
what you are doing.
Objective #5: Define design time, run time, and break time.
- Design time refers to the period of development in which
you carefully plan and design the user interface. You also write out the pseudocode
and the actual code during design time.
- When you are testing and debugging your program, you are in the midst of
run time.
- If an error or bug stops your program, you experience what is called
break time.
Objective #6: Identify compile errors, run-time errors, and logic errors.
- A compile error is often caused by a mispelled keyword or a missing
or misplaced symbol. Incorrect syntax often causes a compile error.
Syntax means the grammar of a programming language. In Visual Basic, compile
errors often cause a line of code to appear in red.
- A run time error often causes a program to stop or crash. These types
of errors can be hard to predict. A typical run time error is caused by dividing
by zero in a program. Since dividing by zero is not a spelling error, it does
not show up highlighted in red as a compile error. Rather, when the program
runs, it causes the program to crash.
- A logic error is often harder to find than compile or run time errors.
A logic error often results in an incorrect computation and incorrect output.
This kind of error does not cause a program to crash in most cases.
Objective #7: List and describe the 3 steps for writing a Visual Basic
project.
- You must always plan a program before you actually write it to be a successful
programmer. Many students and professionals overlook this crucial necessity.
- Design the user interface: You should storyboard
the program by actually drawing pictures of the screen that the user will
interact with during the program's execution. Show the forms and controls
carefully and accurately. Do NOT assume that you will be able to "figure
it out" when you sit down to type the code into the computer. It
is highly recommended to name the forms and controls that you plan to
use beforehand rather than to write them into the code as you type it
as well.
- Plan the properties: Since it is possible to
highly customize the look and feel of a VB program (unlike older procedural
programs), it is very important to write down your ideas and plans before
typing the code into the computer. Your program will not have a commercial
and professional appearance, otherwise.
- Plan the code: Write out pseudocode
that explains the procedural tasks that must be accomplished within your
program before typing or even writing out actual Basic code. Pseudocode
is English phrases that roughly explains how you plan to do things within
your program. Do not use Basic keywords or perfect syntax during this
planning phase.
Objective #8: Know how to place textboxes, labels, and command buttons
on a Visual Basic form.
- One simply needs to double-click on a Toolbox icon in order to place that
object on the form. You may have to drag objects around the form in order
to be able to see newly created ones.
- You can also single-click the Toolbox icon and then click and drag on the
form itself to place and size an object.
Objective #9: Be familiar with the naming convention used for forms,
textboxes, labels, and command buttons.
- You must use the InterCap method with the conventional prefixes
when naming controls and objects. Always begin a control's name with the correct
prefix (3 lowercase letters) that identify the type of control that you are
naming.
- You should always rename the form in your project to frmMain. While VB automatically
assigns the default name of Form1 to the first form in your project, you should
immediately rename it in the Property window. Any other forms that you add
to your project should also have the frm prefix in their name.
- You should always rename textboxes, command buttons and most labels as soon
as you place them on a form. Use logical and relevant names that describe
the purpose of such objects but you must include the prefix lbl with labels,
txt with textboxes, and cmd for command buttons.