Title: BEngBEng Hons Electronics
1BEng/BEng (Hons)Electronics Computing
- Module EEE342M1
- Visual Programming
- Lecture 2
- Creating applications in VB -
- Working with controls
2- Lecturer Anthony McCourt
- Room MG223
- Tele 5556 (internal)
- 028 7137 5556 (external)
- E-mail a.mccourt_at_ulst.ac.uk
- Web http//www.infm.ulst.ac.uk/anthony
3Recap
4The VB Desktop
Properties window
Project window
Toolbox
Form
Pull-down menus
Tool bar
Immediate window
Form layout window
5VB Toolbox
- This is something that you must be familiar with
since you will use the objects on the toolbox to
draw every interface that you create. The figure
on the next slide indicates what is available to
you
6The Toolbox Control
7VB Toolbox
- Pointer Used to select and edit objects
- Picture box A display device which can contain
bit-mapped pictures, text and line drawings - Label Used to display text that the user cannot
change - Text box A text input device which accepts
keyboard input and allows editing. It can format
and display single or multiple lines of text.
8VB Toolbox
- Frame This is an object which allows other
controls to be arranged in logical groups. It
has no behavior on its own. - Command button Operates like a push button,
which is pressed by clicking the mouse on it. - Check box Displays an on or off value. It is
used to display or enter data that can only be
one thing or another.
9VB Toolbox
- Option button Is usually used in a group of
similar controls, and is used to select between a
number of mutually exclusive options. It is also
referred to as a radio button. - Combo box A device that can be used to enter or
select data. It is essentially a single text box
attached to a list. An entry can be typed into
the text box or an existing entry can be
selected. - List box Just like the list part of a combo box.
10VB Toolbox
- Horizontal Scroll bar A control which can be
used to set a level or position of a quantity. - Vertical Scroll bar As above
- Timer Operates by running a piece of program
code at pre-set intervals
11Displaying the time
- Specification Display the time to the nearest
second on a form
1. Open a new project and place two labels on the
form. Caption of left label is The time is.
Delete caption of the right label, set its name
to lblTime and its style property to 1- Fixed
Single 2. Place a timer control on the form. Set
its name to tmrTimer and its Interval property
to 1000. 3. Double click the timer to bring up
the code template for its Timer event and add
the following code,
12Time program continued
- Private Sub tmrTimer_Timer()
- lblTime.Caption Time
- display current time in the label
- End Sub
13Time program continued
- 4. Run the program. Notice you do not see the
timer that you placed on the form but you do
see the time ticking away to the nearest second
14VB Toolbox
- Drive List box A very specialized form of
control which is used to select and display from
a range of disk drives - Directory List box Similar to the drive list
box, but is used to display files in a specific
directory. In general, the three file selection
tools - Drive, Directory, and File Lists - are
used together to allow the user to select an
existing file from a disk, or to specify the name
of a new file. - File List box Use this control to display a list
of files selected by their file attributes.
15VB Toolbox
- Shape Graphical objects, such as circles,
rectangles and rounded boxes can be added to a
visual basic form. - Line Lines, like graphics, can be used to
embellish a form. - Image An image box is similar to a picture box,
but has fewer events to deal with, and so is more
efficient. Image controls are a better choice
for displaying straight-forward bitmaps, and
automatically stretches the bit map to fit the
size of the control, if required.
16VB Toolbox
- Data Control Used to access databases. This
control represents a means of linked your VB
application to an existing database. - OLE Stands for Object Linking Embedding. By
adding an OLE control, you can provide the user
with a means to access other Windows applications.
17Creating Applications
- A VB user interface consists of forms and
objects. - Most VB programs have at least one form.
- Objects are items that appear on a form, such as
command buttons, scroll bars, option buttons,
text boxes, check boxes, etc. - An object enables your program to interact with
the user.
18Creating Applications
- The Visual Basic Application that you create is
composed of several components - Project - the name for a single VB application or
program, stored as .VBP files - Form - a window in the application (a project can
have multiple forms), stored as .FRM files.
Forms contain various objects (from the Toolbox) - Custom Controls - special VB code objects, stored
as .VBX files - Code Modules - programs without any graphics,
stored as .BAS files
19Main Menu Options for Managing Projects
- Running an ApplicationThe first form in a
project (often Form1) is called the startup form. - Ending a ProgramThe statement that stops a
program when it is running is just the End
statement. - Use the Exit caption e.g.Sub
CommandExit_Click EndEnd Sub
20Defining Properties
- After you create a form and draw some objects on
it, the next step is to define the properties of
each form and object. - An objects properties determine the objects
general appearance on the screen. - Different objects have different properties.
- You should always alter the properties to suit
your current application before you start to add
the code that makes the objects work.
21The Properties Window
Object Box - Displays the name of the object for
which you can set the properties
Properties List - The left column displays all
the properties for the selected object the right
column displays the current setting for each
property
22Naming Conventions
- Default name
- e.g. Form1, Picture1
- Change to something more meaningful descriptive
- e.g. frmShape, picMagee, txtFirstName
- Naming convention introduced by Microsoft
- Reduce confusion
- Promote standardization
- Makes maintenance easier
23Naming Conventions for VB
24- For more information on naming conventions and
VBA Programming Standards see
Programming Standards
25Summary
- The text box is used for entering displaying
data - The list box combo box are used for displaying
a list of items from which the user can select an
item. - Two or more option buttons allow the user to
select an option. The Value property holds True
if the button is selected and False otherwise
26Summary
- Any number of check boxes can be selected at the
same time. The Value property holds 1 if the box
is selected and 0 otherwise - A frame is often used to hold groups of option
buttons or check boxes - A timer has a Timer event that is called after an
elapse of time equivalent to its Interval
property - A Visual Basic function returns a value