Return
to IFS 110 class Notes Menu!

Project 4
Menus,
Data Controls,
Common Dialogs, and
General Procedures
Visual Basic Capabilities
- Visual Basic can be used
to build applications that display, edit and
update
information from databases created
by the following DBMS products:
Microsoft Access, dBase, FoxPro, and Paradox.
Project 4 Outline
- Project 4 provides exposure to accessing
a database by building an application that displays
information from a World Geography database created
with Access
- World Geography
database is included on Student
Diskette.
- Project describes only how to display
information. VB can be used to create applications that query, add,
change,
and delete records are covered in
later project.
Common Database Terms
- field - single item of data (characteristic
or attribute )
(graphic image -
country flag)
- record - group of fields (person
or item)
- table - group of related records (file)
- database -collection of related facts organized in a
systematic
manner
- DBMS - database management system -
collection of software that manipulates
a database
Geography Database Viewer
- Geography Database Viewer does not have any
visible
controls
- reason all interaction occurs
by using menus or the
Data
Control
- Select menu - Next, Previous, First and Last
- File menu - Exit
- Options Menu
- View menu Name, Capital, Government
- Font menu Font common
dialog box
- Shortcut menu
can also be used (Options)
Getting Started
- The database file WORLD.MDB and the icon named
Earth.ico used in this project is found on the Student
Disk.
- These files should
be copied to another disk that
will be used later to save
the completed application
Creating the Interface
Note: common dialog
control is not visible at
run-time
Adding Label
Control Array
- Control array - is made
up of a group of controls of the same
type that share
a common control name and
a common set of event procedures
- Array index - a unique index
number is assigned by Visual Basic to
each element of the array starting at 0
Control Array
Continued
Example: Label1(0) can have a caption and
other property
settings different from Label1(1)
Label Array Properties
Adding Common Dialog Control
Adding Data Control
Note: A form can contain more than one
data control, and generally one data
control
exists for each database table accessed by the
application
Geography Database Viewer
Data Control
Creating Menus
Note: When a menu
is open,
you press only the access
key of a command (not the ALT key.)
Example: Exit (press
only the x key)
Menu Concepts
- separator bar - horizontal line used to visually
group related commands in a menu
- submenu
- branches off another menu
to present an additional
set of commands in a separate
grouping
- Visual Basic can have up to four levels of submenu
Setting Properties (steps)
Setting Properties
of Form
CommonDialog Control
Properties
- Flags property used to
set dialog box options
- Flags value = 1
(Font dialog box lists only screen fonts supported by system)
- In Visual Basic, default for FontName
property is determined by
the system.
- Fonts available with VB
vary depending on your system configuration.
For this reason, when Font dialog box displays, a preselected
Font does not exist.
- Must set this FontName
property at design time
or with code at run time
Data Control
Properties
- Caption property - of Data control is text
that displays between
control's next and previous
record buttons
- Align property - determines whether control
can be located anywhere on form or
whether it is sized automatically to fit
the form's width and displayed at the top, left, right, or
bottom of the form
Setting Properties
of Data
Control
Setting Properties
Data-Aware controls
Setting Properties
Data-Aware controls
Setting Properties
Data-Aware controls
- DataSource
property - of
a control specifies the name
of the data
control to which it is bound
- DataField
property of a bound
control specifies the name of a
field in the database to
which the control is linked
- Not necessary to change
caption property of bound labels to blank since captions will take on
field
values of 1st record of table
Writing Code (table 4-2 VB 4.38)
Geography Database Viewer code tasks
- frmGeoView_MouseUp subroutine
- mnuExit_Click subroutine
- Select menu subroutines
- mnuNext, mnuPrev, mnuFirst, mnuLast
- mnuFont_Click subroutine
- mnuView_Click submenu subroutines
- mnuName, mnuCapital, mnuGovt
QueryUnload Event
Select Menu Subroutines
Code statement form
- DataControlName.Recordset.MoveMethod
Example:
Data1.Recordset.MoveNext
Coding EOF statement
Data1.Recordset.MoveNext
If Data1.Recordset.EOF = True Then Data1.Recordset.MoveFirst
Note: If the MoveNext
command causes the current record to move past the
last record, then the first
record in the database becomes the
current record
MouseUp Event
- MouseDown or
MouseUp
event used to specify actions that
will occur when a given mouse
button is pressed or released
- (enable to distinguish among left, right, and
middle
mouse buttons) (2=right)
If Button = 2 Then
PopupMenu mnuOptions
- Options pop-up menu to
display when user right-clicks the
form
- can specify position of pop-up menu, use default
location (current location mouse
pointer)
Using Font Property
Code :
Label1.FontSize = CommonDialog1.FontSize
For...Next statement (loop)
For counter = start
To
end (header
part)
[statements] (repeated)
Next
(terminator
part)
- counter - numeric
variable (loop counter)
- start - initial
value of counter
- end - final
value for counter
- Next - Ends
a For...Next loop; causes 1
to be added to counter
With Statement
Syntax:
With object
[statements]
End With
- Object - is the name
of the object or control
- [statements] - group of code
statements
that operate on object
Potential Problem
- Possible to increase font
size where captions extend beyond
form's right border
Solution: - write
code statements
that adjust form's size (Height and Width) and controls'
locations (Top and Left)
- In GeoView application
code statements adjust the Width of
the form
and center
the Image control right to left
For...Next and
Arrays
- mnuFont_Click
subroutine uses For...Next
loop to set the Font properties of
the 6 labels using
With statement
Coding:
For X
= 0 To 5
With Label1(X)
.FontName = CommonDialog1.FontName
(etc)
End With
Next
General Procedures
General Procedures
Advantage: - when multiple
events
execute similar code, it is more efficient
to put code in a general procedure
and then activate
the general procedure
from the
appropriate events
Example of call: - ToggleView
mnuName, 1
General Procedures
- General procedures may have none or one
or more arguments
(multiple arguments
are separated by commas)
- After the general procedure
is
completed, program control returns
to the code statement
following the one that called
the general procedure
Check Marks in Menus
Code: mnuFlagshow.Checked = True
Project 4
Menus,
Data Controls,
Common Dialogs, and
General Procedures
END
Program
Creating a Database Viewer Application Requirements
Return
to IFS 110 class Notes Menu!
