home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Liren Large Software Subsidy 10
/
10.iso
/
l
/
l407
/
5.ddi
/
VB.LE_
/
VB.bin
(
.txt
)
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
UTF-8
Wrap
Microsoft Lesson
|
1993-04-28
|
270.4 KB
|
2,464 lines
Out of Memory xxx
File Missing
Unrecognized Error
Microsoft CBT
&Instructions
&Back
&Menu
&Summary
E&xit Tutorial
Cancel: Esc
Options
ebugging Your Application
dding Menus5
A.How to Use the Learning Visual Basic Tutorial
Opens this window.-
Jumps to the SummaryA
for that lesson.
Returns to the Menu.t
)Click a lesson name to start that lesson.
(To learn how to use the tutorial, click A
the Instructions button.!
Closes the Options A
menu.X
+When you're done reading the Instructions, A$click the Close Instructions button.8
Closes the tutorial andA
returns to Visual Basic.s
)Click a lesson name to start that lesson.
'To learn how to use the tutorial, clickA
the Instructions button.;
To go forward in a lesson,A
click the Next button. $
reating an Application#
ow Visual Basic Works&
Learning Microsoft Visual Basic%
sing Color and Graphics%
Returns to theA
previous step.
Options<
To go backward in a lesson,A
click the Back button. +
riting Event-DrivenB
Programs5
A.How to Use the Learning Visual Basic Tutorial
nstructions
Clicking the Options button
opens a menu of different
ways to get around in the
tutorial, as shown inA
the diagram at right.0
Working with
orms A
and Controls&
Learning Microsoft Visual Basic.
A'Select a lesson or choose Instructions.j
A red arrow
points to an instruction
'for you to follow to continue with the A tutorial. &Options
E&xit
&Back
&Instructions
&Menu
&Summary
E&xit Tutorial
Cancel: Esc
C&lose Instructions
( O t
. R n
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwww
wwwwwww
wwwxw
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwx
UUUUUUUUUUPx
UUUUUUUUUUPx
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwww
wwwwwww
wwwww
UUUUUUUUUUUWx
UUUUUUUUUUUWw
UUUUUUUUUUUUx
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwww
UUUUx
UwwUUUUWwuW
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwww
wwwwwww
UUUUUUUUUUUU
UUUUUUUUUUUU
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwww
wwwwwwwww
UUUUUUUUUUUUUU
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwww
UUUUUUUU
UUUUUUUUPf`
UUUUUUUP
Pwwwwwwww
wwwwwp
UUUPP
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwww
UUUUP
UUUUP
Form1.frmA
Countries of the World
Summary:,
ile
dit
ountry
Guinea
Population
GRID.VBXA
$2,400 Million
(This lesson introduced you to the Visual
Basic design environment.
.In the following lessons, you'll learn how to @(use Visual Basic to create applications.
Income per Capita
$330.17
OLECLIEN.VBXA
Form1
Form1B
Form1
Form2.
ile
dit
ountry
Next Country
Next Country:
Invalid Country
Label1
<To help you review your code quickly, Visual Basic provides:
Automatic syntax checking
Debugging tools
A Debug window
A cmdCancel
Text1
%Visual Basic includes an easy-to-use
language
that is compatible with
HVisual Basic for MS-DOS, QBasic, Basic Compiler 7.1, and other Microsoft@+Basic products. Language features include:
Form1 B
Form:
You use the
Toolbox to draw
controls on aA
form.F
cmdCancel_Click
NextCountry.
HideA
End Sub
AutoRedraw
A BackColor
BorderStyle
Form1
As a dialog box
ClipControls
Property)
Step through linesA
or procedures.
ControlBox)
A"Form1.ForeColor = RGB(0, 255, 255)
DrawMode
A DrawStyle
A DrawWidth
Enabled-
Integer
Single
DoubleA
Variant
False
&80000005&
2 - Sizable
Caption
13 - Copy Pen
A 0 - Solid
Sweden
ountry
Controls
C are tools such as boxes, buttons, and labels you draw on a form to
Kget input or to display output. They also add visual appeal to your forms.@
You can choose
the View Form
button to display A
a form.7
.A module contains declarations and procedures.A
Currency
String
Japan@
Instead of crowding your formA
with command buttons . . .
dd Watch...
ext Country=
@:You design menus for your forms in the Menu Design window.
Loops<
Print
UCase(
Country
A"Numerous math and string functions
tion:P
Visual Basic displays a
message when it findsA
an error in your syntax.
(none)
nstant Watch...
alls...!
ext Statement6
Set or show the next statementA
to be executed.M
Set and display watch variables.A$List active procedures during break.
Manage breakpoints.T
The Visual Basic language
Menu bars
The Color palette
hortcut:
elpContextID:
Visual Basic also provides a
Color palette
! with 48 standard colors you can @Iuse to add color to your forms. Visual Basic supports 256-color systems._
Set breakpoints, view Instant
Watch, display the Calls A
window, or step through code.
Population
Canada
Next Country
<To help you review your code quickly, Visual Basic provides:
Automatic syntax checking
Debugging tools
Microsoft Visual Basic
Expected: =
Debug Window[Form1]H
Sub Form_GotFocus ( )
! Form1.ForeColor = RGB(128,0,0)A
End SubE
The Immediate
pane is used
to execute singleA
lines of code.r
The Default button resets
the colors of a selected
object to the default colors A
used in Visual Basic.P
This box shows the current textA(color (text is limited to solid colors).
Open or saveA
a project.
Visual Basic [design]
A Options \
Or choose the View
Code button to display
the Code window for A
a module or a form.q
ATo make an application respond to user actions or system events, @+you write code for your forms and controls.h
DIn applications with many commands, Visual Basic lets you group your
commands on a
menu bar@
:You set the properties of forms and controls by using the
CProperties window. Properties specify the initial values for such @,characteristics as size, name, and position.^
BThe Visual Basic toolbar provides shortcuts for many common design@
and debugging commands.>
Open the Menu
Design window or theA
Properties window.#
Open a
new formA
or module.B
Sub Form_Load ( )
Text1.text
"Colombia" A
End Subs
EVisual Basic provides many tools that you can use to design graphical@)applications. This lesson will introduce:
ClickJ
You write code for
your applications
in the Code window.B
Proc:
GotFocus
Object:
Form2
A+A project can also contain custom controls.,
@)You can use forms in many different ways:
Clicking the Options button
opens a menu of different
ways to get around in the
tutorial, as shown inA
the diagram at right.M
Do While
Print
I
Project1
Menu Design Window
Properties?
As an illustrated introductionA
screen to an application
Countries of the World"
Next Statement
dit Watch...
rocedure Step
iA ngle Step
oggle Breakpoint
How Visual Basic Worksw
-Click the Next button ( > ) to continue. To
*return to the Menu or exit Learning VisualA
Basic, click Options.
)Press the PAGE DOWN key to continue with
(this lesson. To choose another part of A.Learning Visual Basic or to exit, press ALT+O.
Opens this window.-
Jumps to the SummaryA
for that lesson.
Returns to the Menu.!
Closes the Options A
menu.%
Returns to theA
previous step.
OptionsX
+When you're done reading the Instructions, A$click the Close Instructions button.
SettingV
(. . . you can organize your commands on A%a menu bar along the top of the form.k
<To help you review your code quickly, Visual Basic provides:
Automatic syntax checkingd
&Click the Menu button to return to the
+Learning Visual Basic Menu. To exit, clickA
Options.
Seven data typesz
The Properties window lists
all the properties and their
settings for the currently A
selected form or control.(
As a document in A
an applicationL
The Watch pane
displays the current
values of watch A
expressions.
project
> is the collection of forms, modules, and custom controls that
Fmakes up an application. The Project window lists all the files in an@
application.8
Closes the tutorial andA
returns to Visual Basic.$
ear All Breakpoints5
A.How to Use the Learning Visual Basic Tutorial 5
A.How to Use the Learning Visual Basic Tutorial
A 7,269,000
$2,400,000,000
EYou create forms to serve as the interface of your application. Each@Bform is a window that displays controls, graphics, or other forms.@
[Form1.frm] BackColor: 0A
[Form1.frm] ForeColor: 16776960
@ includes the controls and code associated with that form. When
Gyou want to share code throughout a project, you can put that code in a
module@
If...Then...Else blocksv
Pop
GNP
Income
GNP
Income
End If?
As an illustrated introductionA
screen to an application]
&This box shows the current foreground
%and background colors of the selectedA
object.
Module1.basB
Form1.frmB
Form1B
nabled
isible
indow List
hecked
To go forward in a lesson,A
click the Next button. <
To go backward in a lesson,A
click the Back button. X
(A form file contains the description of A'a form and the code associated with it.
As a dialog boxj
A red arrow
points to an instruction
'for you to follow to continue with the A tutorial.B
Projects
Forms and controls
Modules_
,To return to the Learning Visual Basic Menu,A*press the SPACEBAR. To exit, press ALT+O.
You can display this
window by choosing the
Menu Design command
from the Window menu or
choosing the Menu DesignA
button on the toolbar..
ile
dit
ountry
EBy combining the Visual Basic forms, tools, and programming language,@7you can build powerful applications quickly and easily.<
Start, break, or
end execution A
of an application.c
ile
dit
iew
un
ebug
ptions
indow
elp &Options
View Form
View Code
Cancel
Next Country
Add Country
Edit Country
Insert
Delete
Default
Custom Colors >>
&Back
&Instructions
&Menu
&Summary
E&xit Tutorial
Cancel: Esc
&Close Instructions
wwwwwwwwp
wwwwwwwwp
wwwww
wwwwwwwwp
wwwwwwwwp
wwwwwwwwwwwwp
wwwwwwwwwwwwp
wwwwwwwwwwwwpwwwwwwwwwwwww
wwwwwwwwwwwwp
wwwwwwwwwwww
wwwwwwwwwwwwpwwwwwwwwwwwww
wwwwwwwwwwwwp
wwwwwwwwwwww
wwwwwwwwwwwwpwwwwwwwwwwwww
wwwwwwwwwwwwp
wwwwwwwwwwww
wwwwwwwwwwwwpwwwwwwwwwwwww
wwwwwwwwwwwwp
wwwwwwwwwwww
wwwwwwwwwwwwpwwwwwwwwwwwww
wwwwwwwwwwwwp
wwwwwwwwwwww
wwwwwwwwwwwwpwwwwwwwwwwwww
wwwwwwwwwwwwp
wwwwwwwwwwww
wwwwwwwwwwwwpwwwwwwwwwwwww
wwwwwwwwwwwwp
wwwwwwwwwwww
wwwwwwwwwwwwpwwwwwwwwwwwww
wwwwwwwwwwwwp
wwwwwwwwwwww
wwwwwwwwwwwwpwwwwwwwwwwwww
wwwwwwwwwwwwp
wwwwwwwwwwww
wwwwwwwp
wwwwwwp
wwwwwwwp
wwwwwwp
wwwwwwwp
wwwwwwp
wwwwwww
wwwwwww
wwwwwwwp
wwwwwww
wwwwwww
wwwwwwp
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwp
wwwwwwp
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwp
wwwwwwwwp
wwwwwwx
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwwp
wwwwwwwwww
wwwwwwwwwwp
wwwwwwwwww
wwwwwwwwwwp
wwwwwww
wwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwww
wwwwwwwwwwp
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwww
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwww
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwwp
wwwwwwwwww
wwwwwwwwww
wwwwwwwwwwp
wwwwwwwwwwp
wwwwwwwwww
wwwwwwwwww
wwwwwwwwwwp
wwwwwwwwww
wwwwwwwwww
wwwwwwwwwwp
wwwwwwwwww
wwwwwwwwwwp
wwwwwwwwww
wwwwp
wwwwww
wwwwwwwwwwwww
wwwwwww
wwwwwww
wwwwwww
wwwwwww
wwwwwww
wwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwp
wwwwwwwp
wwwwwww
wwwwwwp
wwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwx
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwp
wwwwwwwp
wwwwwwp
wwwwwwp
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwp
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwww
wwwwwwwwwwp
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwww
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwww
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwwpwwwwwwwwwww
wwwwwwwwwwp
wwwwwwwwww
wwwwwwwwww
wwwwwwwwwwp
wwwwwwwwwwp
wwwwwwwwww
wwwwwwwwww
wwwwwwwwwwp
wwwwwwwwww
wwwwwwwwww
wwwwwwwwwwp
wwwwwwwwww
wwwwwwwwwwp
wwwwwwwwww
wwwwp
wwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwww
Clicking the Options button
opens a menu of different
ways to get around in the
tutorial, as shown inA
the diagram at right.
Summary:
BVisual Basic applications, which are event-driven, allow users to
@control how they enter information. Visual Basic makes it easy
Bto create standard applications in the Microsoft Windows operating@
system.
Action
*Button is selected with mouse or keyboard.
!Control is dropped on the button.
#Control is dragged over the button.
Button gets the focus.
*Key is pressed while button has the focus.
,Key is pressed, and ASCII value is returned.
+Key is released while button has the focus.@
Button loses the focus.T
The event name is the
action that triggers theA
code in the event procedure.\
cmdChange_Click ( )
ChangeSignal
' Call the procedureA
End Sub
:In a traditional programming environment, users must enter
Ainformation in an order determined by the application programmer.@BFor example, they have to answer the following questions in order.
EA Visual Basic application's interface is made up of objects -- forms
?and controls. Each object recognizes actions, such as the user
?clicking a button, opening a form, or typing in a field. These
actions are referred to as
events@
<By clicking the OK button, you've run the code in this event@Bprocedure. Every time the button is clicked, the code runs again.
DWhen an event occurs in your application, Visual Basic automatically
Brecognizes the event and runs the code that you've written for it.
This code is called an
event procedure@
>Each form and control in Visual Basic responds to a predefined
<set of events. For example, a command button recognizes the@
following events.
AFor example, you might want to check the contents of the text box
$when the user chooses the OK button.
@<Clicking the OK button triggers the cmdOKButton_Click event.
cmdOKButton_Click ( )
txtState.Text = ''WA''
OrderFormWA.Show
OrderFormGeneral.ShowA
End SubI
The object name is the
form or control toA
which you attach code.
Object8
Closes the tutorial andA
returns to Visual Basic.j
A red arrow
points to an instruction
'for you to follow to continue with the A tutorial.
Event procedures can also:
Trigger other event procedures.
Change an object's properties.
@=Call other general procedures that are not tied to any event.F
)Press ENTER or click the OK button to runA
the event procedure.v
Event procedures can also:
Trigger other event procedures.
Change an object's properties.
EAn event procedure runs only when the event occurs, and Visual Basic
Oremains idle until that happens. You can see how this works for the OK button.
Click the OK button or press
ENTER@
Event
Click
DragDrop
DragOver
GotFocus
KeyDown
KeyPress
KeyUp@ LostFocus
Personnel Information
Address:
Name:
City:
State:
Project1
Enter your name > Joe Smith
#Enter your address > 555 Cedar LaneA
Enter your city >_
A Joe Smith
98555
Redmond
Controls
TextA
= '' '' Then
Sub cmdOKButton_Click ( )
If txtName.Text = '' '' Then
$ MsgBox ''Enter your name.''
End IfB
End Sub
Sub cmdOKButton_Click ( )
If txtName.Text = '' '' Then
$ MsgBox ''Enter your name.''
End IfA
End Sub
Sub cmdOKButton_Click ( )
If txtName.Text = '' '' Then
MsgBox
''Enter your name.''
End IfA
End Sub
Sub cmdOKButton_Click ( )
txtName.Text
'' ''
$ MsgBox ''Enter your name.''
End IfA
End Sub
=You need to write code only for the events that you want your
application to respond to.
DTo determine which events to write code for, you need to think about@?what the user will do, and how you want the program to respond.
>Event procedure names combine the control name, an underscore,
8and the event name. So the event procedure name for the
"cmdOKButton's Click event would be
cmdOKButton_Click.
AAn event procedure name is made up of an object name and an event
Gname. The object name for all forms is Form. For controls, the object
@name is the control's Name property. There can be one or more @!statements in an event procedure.
"This lesson will introduce you to:
Event-driven programming
Event procedures
o @
Syntax for eventsw
-Click the Next button ( > ) to continue. To
*return to the Menu or exit Learning VisualA
Basic, click Options.
Opens this window.-
Jumps to the SummaryA
for that lesson.
Returns to the Menu.!
Closes the Options A
menu.%
Returns to theA
previous step.
OptionsX
+When you're done reading the Instructions, A$click the Close Instructions button.O
Event procedures can also:
Trigger other event procedures.
This lesson covered:
Event-driven programming
Event procedures
Syntax for events
%For more information on event-driven
programming, see the lesson
-''Debugging Your Application'' or Chapter 6,
$''Programming Fundamentals,'' in theC
Programmer's Guide.
chkBold_Click ( )
If
chkBold.Value = 1
Then
txtDisplay.FontBold =
End IfA
End Subd
&Click the Menu button to return to the
+Learning Visual Basic Menu. To exit, clickA
Options.B
cmdDelete_Click ( )
mnuDelete_ClickA
End Sub
:Visual Basic is a programming system that you use to write
event-driven applications
(. Programming in response to particular
Fevents, such as a key press or a mouse click, makes it easy to create @;applications that are visually appealing and simple to use.
Period
cmdOKButtonv
If txtName.Text = '' '' Then
$ MsgBox ''Enter your name.''
End IfA
End Sub
Click B
txtName
Sub cmdOKButton_Click ( )
If
$ MsgBox ''Enter your name.''
End IfA
End Sub5
A.How to Use the Learning Visual Basic Tutorial 5
A.How to Use the Learning Visual Basic Tutorial
Sub cmdOKButton_Click ( )
If
txtName.Text
= '' '' Then
$ MsgBox ''Enter your name.''
End IfA
End Sub
cmdOKButton_Click
If txtName.Text = '' '' Then
$ MsgBox ''Enter your name.''
End IfC
End Sub
cmdOKButton_Click
txtName.Text
'' ''
MsgBox
''Enter your name.''
End IfA
End Sub
;You refer to a control and its properties in code using the
Eobject.property notation. For example, to refer to text displayed in@,a text box, the syntax would look like this:
Enter your name.
Property"
cmdOKButton_Click B
Statements are the
code you want to runA
when the event occurs.
Name;
To go forward in a lesson,A
click the Next button. <
To go backward in a lesson,A
click the Back button. $
Writing Event-Driven Programs
Underscore
Event_
,To return to the Learning Visual Basic Menu,A*press the SPACEBAR. To exit, press ALT+O.
)Press the PAGE DOWN key to continue with
(this lesson. To choose another part of A.Learning Visual Basic or to exit, press ALT+O.
Form &Options
&Back
&Instructions
&Menu
&Summary
E&xit Tutorial
Cancel: Esc
&Close Instructions
Summary:
2. Set properties
You set the properties of a
!control in the Properties window.
#When you select a form or control,
"its properties and their settings
are displayed in the Properties @
window.
Form1
Creating an Application
Every new project contains one
form. You can add as many
additional forms as your
application needs.
The Temperature Conversion
application requires only one@
form.
Form1
Celsius:
Fahrenheit:+
Code that controls A
the application
KeyPressh
*Sub txtCels_KeyPress (KeyAscii As Integer)
, txtFahr.Text = 9/5 * (txtCels.Text) + 32A
End Sub
project
includes:
Forms -- backgrounds,
windows, and dialog boxes.
Controls -- graphical objects
placed on forms.
procedures and
@
declarations.
Proc:
Object:6
Text boxes for
entering and A
displaying text
A form
$There are three steps to creating an
application:
Create the interface.
Set properties.
Write code.
3. Write code
To make the application respond
"to the user's actions, we'll write
event procedures for the text
boxes.
These event procedures are @
triggered by a KeyPress event.
This form is the background of
the application.
We can change the size and
location of the form to fit the@
application's design.{
.Type a number in the text box, and then press
,ENTER. To continue with the tutorial, clickA
the Next ( > ) button.
Next, we'll select the tools we
need from the Toolbox to draw
!the controls we want on the form.
In this application, text boxes
accept user input and display
text.@
We'll create two text boxes, one
for Fahrenheit temperatures and
one for Celsius temperatures.
When the user enters a
temperature in one of the text
"boxes, the equivalent temperature @#is displayed in the other text box.`
The pieces of the application
are now in place. To make it @
work, we need to add the code.b
Once you save a project, you
can go back and change its
appearance or operation at any@
time.i
To describe the contents of each
text box, we'll use labels.
Labels can't be changed by the@
user.
#We'll use the following formulas to
convert the temperatures:
Cels = (Fahr - 32) * 5/9
Fahr = (Cels * 9/5) + 32
"Next, we'll enter the code for the@
event procedure.
The Procedure list box contains
!a list of events for the control.
"Selecting the KeyPress event from
$the Procedure list box displays the
!template for the event procedure @
we want to write.
Now, we'll change the Name
property of the other text
box to txtFahr and the Caption
property of its label to @
Fahrenheit.E
Now we'll attach a similar event@ procedure to the other text box.
To try out the application:
Type values in the text box,
and press
ENTER
to convert @
the temperature.
When you finish working on your
application, you'll want to save
the project.
Choosing Save Project from the
File menu prompts you to assign@
a name to the project.#
@ The application is now complete.
You can test your application by
choosing Start from the Run menu
or clicking the Start button (
the toolbar.
You can also use the debugging
tools to help locate and fix @
problems in your application.
(This lesson demonstrated how to create a
simple application:
1. Create the interface.
2. Set properties.
3. Write code.
/The lessons that follow explain the parts of a @(Visual Basic application in more detail.
Enter a temperature:M
:As you run your application, you might also think of ways @
to improve it.
%Provide a graphical way to enter and A+display the temperatures using scroll bars.R
%Add a command button that clears the A$temperatures from both text boxes.
When your application is exactly
the way you want it, you can
make it into an executable file.
!This allows you, and other users,
#to run the application outside the @
Visual Basic environment.
Celsius:
Fahrenheit:
When the user types a
temperature in one of the text
boxes and presses
ENTER
, the
!code updates the contents of the @
other text box.w
-Click the Next button ( > ) to continue. To
*return to the Menu or exit Learning VisualA
Basic, click Options.j
,Click the Menu button ( > ) to return to the
+Learning Visual Basic Menu. To exit, clickA
Options.
Opens this window.-
Jumps to the SummaryA
for that lesson.
Returns to the Menu.!
Closes the Options A
menu.%
Returns to theA
previous step.
OptionsX
+When you're done reading the Instructions, A$click the Close Instructions button.h
Assist the user by providing
&instructions and checking for invalid A
entries in the text boxes.
CThis lesson demonstrates how to build a Visual Basic application.
@EThe application converts temperatures between Fahrenheit and Celsius.
1. Create the interface
To create an application, you
!first need to open a new project.
You open a project by choosing
the New Project command from@
the File menu.
The Caption property specifies
!the text that is displayed in the
#control. We'll change the label's @
Caption property to Celsius.5
A.How to Use the Learning Visual Basic Tutorial 5
A.How to Use the Learning Visual Basic Tutorial k
To create an executable file
from your project, you use the
Make EXE File command from@
the File menu.
%To create a control, select the tool
from the Toolbox, and then hold
down the left mouse button while
!dragging out an area on the form.
You can create a control in the
default size by double-clicking
!the tool or selecting a tool and
pressing
ENTER@
Labels
)You can't go back from this point in the
%lesson. To review the lesson, chooseA&Creating an Application from the Menu.;
To go forward in a lesson,A
click the Next button. <
To go backward in a lesson,A
click the Back button.
Clicking the Options button
opens a menu of different
ways to get around in the
tutorial, as shown inA
the diagram at right.8
Closes the tutorial andA
returns to Visual Basic.j
A red arrow
points to an instruction
'for you to follow to continue with the A tutorial.E
@BThe Temperature Conversion application consists of these elements:_
,To return to the Learning Visual Basic Menu,A*press the SPACEBAR. To exit, press ALT+O.
)Press the PAGE DOWN key to continue with
(this lesson. To choose another part of A.Learning Visual Basic or to exit, press ALT+O.~
You use the Name property to
%refer to a control in code. In this
case, we'll make txtCels the @
name of this text box.
When you double-click a control,
the focus shifts to the Code
window. The code template for
the selected control's default
event procedure is displayed.
The name of the control appears @
in the Object list box. &Options
&Menu
Update
txtCels
Celsius:
txtFahr
Endif
Fahrenheit:
&Back
&Instructions
&Summary
E&xit Tutorial
Cancel: Esc
'txtCels.Text = Val(txtFahr.Text-32)*5/9.If (KeyAscii=13)Then ' keyascii 13 = Enter key-txtFahr.Text = 9 / 5 * Val(txtCels.Text) + 32,
&Close Instructions
z [ z
n , -
wwwwwww
wwwwwww
wwwwwww
wwwwwww
One minute....
...files are being loaded.
After you enter the caption and
name, you can click the Next
button or press
ENTER
to create
the File menu control.
"The highlight then moves to a new
#line, and the text boxes are reset
to accept the next caption and @
name.
ountryi
=Menus consist of menu titles, menu items, and separator bars.@'Every part of a menu is a menu control.
Separator bar
A Menu item
ountry
Sweden
Menu title
Population
Income per Capita
$A menu is a control, like a text box
!or a command button. Like other
!controls, a menu has a predefined@
set of properties and events.
To distinguish menu items from
menu titles, you indent the menu
!items in the lower portion of the
Menu Design window.
To indent a menu item, select it
and then click the right arrow @
button.
Create the File menu
"The text you enter in the Caption
text box defines the menu name.
!This is the text that appears on
the menu bar.@
The text in the Name box defines
the menu's Name property. This
!is used to refer to the File menu@
in code.
In addition, you can set other
menu properties in the Menu
Design window.
After you have created a menu,
you can change its property
"settings in either the Menu Design@ window or the Properties window.
specifies a menu title, such
" as File or Edit, or an item on
a menu, such as Open or Cut.
the name used to refer to the
menu control in code.
a numeric value that uniquely
% identifies the menu control if it A
is part of a control array.q
.You use the Menu Design window to create menu
"controls and set their properties:
Caption@
.You use the Menu Design window to create menu
"controls and set their properties:
Caption
Index
ext Country
The File menu now consists of
one command -- Exit.
Next, we'll add the second menu
!to the menu bar -- Country -- and
a command to the Country @
menu -- Next Country.
ind...
Inserting an ampersand (&)
before a letter gives the user
keyboard access to the menu.
At run time, this letter will be
underlined.
"For example, in this menu the user
could select the File menu by
pressing A
ALT+F.
Adding Menus
Opens this window.-
Jumps to the SummaryA
for that lesson.
Returns to the Menu.!
Closes the Options A
menu.%
Returns to theA
previous step.
OptionsX
+When you're done reading the Instructions, A$click the Close Instructions button.w
-Click the Next button ( > ) to continue. To
*return to the Menu or exit Learning VisualA
Basic, click Options.
Open the Menu Design window
You use the Menu Design window
to create menus for your form.
Switch to the form to which you
want to add a menu, and then @
open the Menu Design window.
GThis lesson will demonstrate how to create menus in Visual Basic using
'the Countries of the World application.
DThis application has two menus on its menu bar: File and Country. @CThe commands on the menus remain hidden until the menu is selected.
revious Country
eA w Country5
A.How to Use the Learning Visual Basic Tutorial
This lesson covers:
The Menu Design window
Menus and menu commands
Menu design guidelines5
A.How to Use the Learning Visual Basic Tutorial
Add the Exit menu command
To add the Exit command to the
File menu, we'll enter E&xit in
the Caption box.
In the Name box, we'll enter
mnuFileExit to refer to the Exit@
command in code.
(The example files needed for this lesson
)cannot be found. To run this lesson, youA(need to reinstall Learning Visual Basic.;
To go forward in a lesson,A
click the Next button. <
To go backward in a lesson,A
click the Back button.
Clicking the Options button
opens a menu of different
ways to get around in the
tutorial, as shown inA
the diagram at right.8
Closes the tutorial andA
returns to Visual Basic.j
A red arrow
points to an instruction
'for you to follow to continue with the A tutorial.
)Press the PAGE DOWN key to continue with
(this lesson. To choose another part of A.Learning Visual Basic or to exit, press ALT+O.
.You use the Menu Design window to create menu
"controls and set their properties:
Caption
specifies a menu title, such
" as File or Edit, or an item on
a menu, such as Open or Cut.
the name used to refer to the A
menu control in code.w
specifies a menu title, such
" as File or Edit, or an item on A
a menu, such as Open or Cut.
You open the Menu Design
window by choosing the Menu
Design command from the
Window menu or choosing the
Menu Design button from the@
toolbar. &Options
&File
mnuFile
mnuFileExit
&Back
&Instructions
&Menu
&Summary
E&xit Tutorial
Cancel: Esc
E&xit
sweden.frm
Return to &Menu
E&xit Learning VB
country.mak,
&Close Instructions
Summary:
Select mnuFileExit from the
Object box
We entered mnuFileExit as the
Exit command's Name property.
The Name property is used@
to refer to a control in code.
Write the code
We'll write code to make the
application respond to the Exit
command. The code goes
between the Sub and End Sub
statements in the Code window.@
The code we entered ends the @#Countries of the World application.
Separator A
New...
Open...
Close the Menu Design window
When you close the Menu
Design window, the menus are
automatically displayed on the@
form.
BWhen creating menus, follow these standard menu design guidelines:
)Group related commands on a menu in a way
2that will make sense to users of your application.
+For example, users familiar with Microsoft
*Windows may expect to find the New, Open,
/and Close commands together on the File menu.
,Look at existing Windows-based applications
for examples.
*On long menus, separate groups of related
*commands with a separator bar. Separator
.bars are created by using a single hyphen (-)
@-in the Caption box of the Menu Design window.
Adding Menus
Opens this window.-
Jumps to the SummaryA
for that lesson.
Returns to the Menu.!
Closes the Options A
menu.%
Returns to theA
previous step.
OptionsX
+When you're done reading the Instructions, A$click the Close Instructions button.w
-Click the Next button ( > ) to continue. To
*return to the Menu or exit Learning VisualA
Basic, click Options.d
&Click the Menu button to return to the
+Learning Visual Basic Menu. To exit, clickA
Options.
When the user clicks a menu
"title, Visual Basic automatically
displays its menu.
To define how each menu
command responds to a Click
event, you write an event@
procedure for each command.
Close
Save As...5
A.How to Use the Learning Visual Basic Tutorial 5
A.How to Use the Learning Visual Basic Tutorial
Menu commands respond only
#to Click events. If a user selects
a menu item when the application
!is running, the associated Click @
event procedure is executed.;
To go forward in a lesson,A
click the Next button. <
To go backward in a lesson,A
click the Back button. t
)You can't go back from this point in the
%lesson. To review the lesson, chooseA
Adding Menus from the Menu.
Clicking the Options button
opens a menu of different
ways to get around in the
tutorial, as shown inA
the diagram at right.8
Closes the tutorial andA
returns to Visual Basic.j
A red arrow
points to an instruction
'for you to follow to continue with the A tutorial.
Open the Code window
"You write event procedures in the
Code window.
To open the Code window for a
form, choose View Code from the
Code menu, or press
%This lesson showed you how to create
)menus for your Visual Basic applications
using the Menu Design window.
'For more information on creating menus,
&see Chapter 4, ''Menus and Dialogs,''
in theA
Programmer's Guide._
,To return to the Learning Visual Basic Menu,A*press the SPACEBAR. To exit, press ALT+O.
)Press the PAGE DOWN key to continue with
(this lesson. To choose another part of A.Learning Visual Basic or to exit, press ALT+O. &Options
&Country
mnuCountry
&Next Country
mnuCountryNextCountry
&Back
&Instructions
&Menu
&Summary
E&xit Tutorial
Cancel: Esc
&Close Instructions
The Properties
list displays all
the available
properties for
the selectedA
form or control.
Command ButtonG
The Object box
shows the currently
selected form orA
control.
Form1
Form1 B
AutoRedraw
A BackColor
BorderStyle
Form1
ClipControls
ControlBox
DrawMode
A DrawStyle
A DrawWidth
Enabled
False
&80000005&
2 - Sizable
Caption
Payment Amount:
&The drive list box finds and switches
$among valid drives at run time. It
+displays a list of the user's valid drives.
*You can use the drive list box control as A)part of a dialog box used to open a file.
You draw graphical objects
called
controls
on a form to
accept user input or display
output.
You draw a control by selecting@"one of the tools from the Toolbox.
Pointer
*A text box is an area in which text can be
'entered by the user or displayed by the
(application. A text box can contain one
or more lines of text and can be
scrollable.
!For example, in a security-system
(application, you might use a text box toA
prompt a user for a password.
Label
+The file list box displays all the files in
%a given directory. You can display a
+list of files based on file attributes, and
&users can select a file from the list.
(You can use a file list box as part of aA
dialog box used to open a file.
File List Box
'A timer can be used to cause actions to
&occur at regular intervals while your
application is running.
$For example, you can use a timer to A+update a clock display in your application.
Directory List Box
%The shape control displays a circle,
square, oval, rectangle, rounded
%rectangle, or rounded square. Unlike
&graphics methods, the shape control is
visible at design time.
'For example, you can use shape and line
*controls to create a graphic of a building
layout.A
Drive List Box
(A picture box control is used to display
*graphics on your form and to draw graphics
+in code. It can display a bitmap, icon, or
+metafile. As much of the picture as can be
.displayed within the picture rectangle will be
shown.
)You can create animation in a picture box
+by manipulating the graphics properties andA
methods.
Timer
%A line control displays a horizontal,
(vertical, or diagonal line. You can use
%line controls to draw lines on forms.
)Unlike the Line method, line controls are
visible at design time.
*You can use lines to display callouts on aA*graphic or to divide a form into sections.
Vertical Scroll Bars
Horizontal Scroll Bars
.An option button is used to select an option,
%usually from among a group of option
-buttons. When an option button is selected,
)the button has a black center. Unlike a
&group of check boxes, only one option
$button can be selected from a group.
,For example, you might use an option button
(group to indicate the method of payment A-(cash, check, or credit card) for an invoice.
Picture Box
A Combo Box
-Horizontal scroll bars allow the user to move
*horizontally within lists or through large
,amounts of information. They also provide a
'graphical way of displaying and setting
values.
'For example, you could use a horizontal
0scroll bar to set the volume for an application
*that plays music or to show how much time
has elapsed.A
Option Button
A Check Box
Option Button
Frame
Image
Text Box
Clicking the Options button
opens a menu of different
ways to get around in the
tutorial, as shown inA
the diagram at right.
&A combo box combines a text box and a
+list box. The user can either type in the
+text box or select items from the list box.
%There are three types of combo boxes:
$drop-down combo boxes, simple combo
boxes, and drop-down list boxes.
%You can use drop-down combo boxes andA'list boxes to save room on your forms.
Image
Picture Box
List Box
Shape
$A label displays text that cannot be
%changed by the user. The text can be
'changed by the application at run time,
!however, in response to an event.
*You can use a label to display information
*for the user. For example, you could show
*the time or the progress of a file-copyingA
operation.
13 - Copy Pen
This option button group will
!consist of a frame and two option
buttons.
To put an object inside another
object, you must create the
container first, and then place@
the object inside it.
A 0 - Solid
Properties
Each tool in the Toolbox creates
a unique control. Each control
has built-in capabilities.
For example, Visual Basic allows
#users to cut and paste text in text
boxes without requiring you to @
write any code.
In earlier lessons, you've seen
how to add a control to a form.
Here, we've designed a form
with one label and one text box.
Next, we'll add an option button
group to the form to let users@!indicate their method of payment.
,An image control is a graphical control that
0can display a picture. It is like a picture box
*control but uses fewer resources, repaints
%faster, and supports only some of the
+picture box properties, methods and events.
&For example, you can place a bitmap of
)your company logo in an image control and
,display text about the company when the userA
clicks it./
One minute....
...files are being loaded.
Command Button
Directory List Box
A Check Box4
!Click the control in the Toolbox.B
A Combo Box
A frame provides a graphical and
*functional grouping for controls. Objects
$are put into frames to separate them
visually from other controls.
'You can place option buttons in a frameA!to create an option button group.
Drive List Box
File List Box
Frame
Horizontal Scroll Bars
*A list box contains a scrollable list from
%which the user can select one or more
items.
&For example, you can display a list of
%names in a list box and have the userA
choose from the list.
Label
List Box
Pointer
Shape
Text Box
Timer
Vertical Scroll Bars
Opens this window.-
Jumps to the SummaryA
for that lesson.
Returns to the Menu.!
Closes the Options A
menu.%
Returns to theA
previous step.
OptionsX
+When you're done reading the Instructions, A$click the Close Instructions button.$
@!To learn more about each control:w
-Click the Next button ( > ) to continue. To
*return to the Menu or exit Learning VisualA
Basic, click Options.
#The directory list box displays the
*directories and paths of the current drive
)at run time. You can use this control to
*display a hierarchical list of directories
#from the root to the selected path.
*You can use the directory list box as partA$of a dialog box used to open a file.
.Every form and control has a predefined set of
properties
. These properties determine:
Appearance
Behavior
When you create a form, it is
initially displayed in a default
location and size. You can
change both the location and the
#size of the form to suit the design
of your application.@
Payment MethodI
@FYou set the initial values for properties using the Properties window.J
The Settings box
contains a property
setting that you A can edit.
Charge Information
!The pointer is used to manipulate
)existing controls on your form. With the
'pointer, you can select, move, and size
forms and controls.
When you select a tool from the
&Toolbox, your mouse pointer changes to
*a cross hair. After you create a control,
&your mouse pointer changes back to the
pointer.
A.How to Use the Learning Visual Basic Tutorial 5
A.How to Use the Learning Visual Basic Tutorial
= is a window or dialog box that you create with Visual Basic.
@FIn this lesson, we will build a form that accepts payment information.
+A check box is used for an option that can
-be turned on and off. When the user selects
+the option, an X is displayed in the check
*box. Check boxes can be used to give the
#user a yes/no or true/false option.
#You can use check boxes for options
*that users can select in any combination,
$such as bold, italic, and underline A
formatting.&
Working with Forms and ControlsH
Setting properties
Creating event procedures
*The grid control displays a series of rows
+and columns. At the intersection of a row
,and a column is a cell. A cell can contain
pictures or graphics.
(You can use a grid control to display a A
table of information.
OLE Client
OLE Client
Payment
(The example files needed for this lesson
)cannot be found. To run this lesson, youA(need to reinstall Learning Visual Basic.
Cash/Check
Charge
A MajorCard
Viva!
AreMax;
To go forward in a lesson,A
click the Next button. <
To go backward in a lesson,A
click the Back button. N
This lesson will introduce:
Forms
Adding controls
,Vertical scroll bars allow the user to move
)vertically within lists or through large
+amounts of information. They also provide
*a graphical way of displaying and setting
values.
+For example, you could add vertical scroll
bars to a temperature conversion
'application to show temperatures risingA
and falling.8
Closes the tutorial andA
returns to Visual Basic.j
A red arrow
points to an instruction
'for you to follow to continue with the A tutorial.
)Press the PAGE DOWN key to continue with
(this lesson. To choose another part of A.Learning Visual Basic or to exit, press ALT+O.
-- the color, size, and name
of the form.
-- whether the user can move,
size, minimize, or maximize
-- @ the form.
&A command button carries out an action
)when the user chooses it. Typically, the
user chooses a command button by
clicking it or by pressing the
SPACEBAR
when it is selected.
%OK and Cancel buttons are examples of
%command buttons. Or you might create
a command button that a user canA
choose to open another form.
(The common dialog custom control allows
%you to display several commonly used
+dialog boxes: Open, Save As, Print, Color,
and Font.
&When you draw a common dialog control
,on a form, it automatically resizes itself.
*Like the timer control, the common dialog
!control is invisible at run time.A
Data Access
Data Access
Common Dialog
Common Dialog
+The OLE control lets you display data from
*another Windows-based application in your
Visual Basic application.
-At run time, you can edit the data in an OLE
-control from within the application in which
,it was created. When you finish your edits,
+you close the application, and the updated
(data is displayed in the OLE control on
your form.A
.The data control lets you create applications
.to display, edit, and update information from
+many types of existing databases. You can
,use other data-aware controls with the data
(control to display information from the
current record in a database.
'Visual Basic implements data access by
'incorporating the same database engine
that powers Microsoft Access.A
&Options
Payment.mak
&Back
&Instructions
&Menu
&Summary
E&xit Tutorial
Cancel: Esc
payment.mak form2.frm
payment.frm
Return to &Menu
E&xit Learning VB
&Close Instructions
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp
wwwwwwwwwwwwp
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp;)
wwwwwwwwwwwwp
@ BM6
wwwwwwwwwwwwp
wwwwwwwwwwwwpLT
wwwwwwwwwwwwp
wwwwwwwwwwwwp
fOBMb!
wwwwwwwwwwwp
wwwwwwwwwwwp
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwpwwwwwwwwwwww
wwwwwwwwwwwp
wwwwwwwwwww
wwwwwwwwwwwwp
wwwwwwwwwwwwpLT
wwwwwwwwwwwwp
wwwwwwwwwwwwpLT
To go forward in a lesson,A
click the Next button.
Summary:<
To go backward in a lesson,A
click the Back button. m
Watch as we run the Payment
application and switch between
the Cash/Check and the Charge
buttons.
We now have a control array
consisting of the two option
buttons.
Now we'll add the frame and
controls for the charge@
information.
To add code to the project, you
need to open the Code window.
To view the code for a control,
you can double-click the control
or press
when the control is@
active.
The Click event for the option
#button array is loaded in the Code
!window. Notice that it contains
the parameter Index
As Integer
Here, Index is used to refer to
individual items in the control
array.
Now, watch as we add the code.
The charge information should be
displayed only when the Charge
button is selected.
$We'll hide it by setting the Visible
property for the Charge @
Information frame to False.
Although the Visible property is
set to False, you can still see
the frame at design time. This
!makes it easier for you to design@ the form.
"That's all there is to creating a
!form, adding controls, and adding
code to make your application@
respond to user input.
The two option buttons we'll
"create inside this frame will be a
control array.
A control array consists of
controls of the same type that
share a common name and@
common event procedures.w
-Click the Next button ( > ) to continue. To
*return to the Menu or exit Learning VisualA
Basic, click Options.
Opens this window.-
Jumps to the SummaryA
for that lesson.
Returns to the Menu.!
Closes the Options A
menu.%
Returns to theA
previous step.
OptionsX
+When you're done reading the Instructions, A$click the Close Instructions button.
To put a control inside a frame,
you draw it on top of the frame
using the mouse, or you use the
Paste command when the frame
has the focus.
Watch as we add the two option
buttons inside the frame and set@
their Caption properties.d
&Click the Menu button to return to the
+Learning Visual Basic Menu. To exit, clickA
Options.
The next step is to add code to
the form. We want to write code
that makes the charge
information visible when the@
Charge button is selected.a
When you create a duplicate
name, Visual Basic asks if you
want to create a control array.@
A.How to Use the Learning Visual Basic Tutorial 8
Watch as we create the frame@
and set its properties.
$This lesson introduced you to forms,
*controls, properties and control arrays.
'The next lesson covers adding menus to
forms.
(For more information on designing forms,
(see Chapter 2, ''Your First Visual Basic
(Application,'' and Chapter 3, ''Creating
and Using Controls,'' in theA
Programmer's Guide.5
A.How to Use the Learning Visual Basic Tutorial &
Working with Forms and Controls
)You can't go back from this point in the
.lesson. To review the lesson, choose Working A&with Forms and Controls from the Menu.
Clicking the Options button
opens a menu of different
ways to get around in the
tutorial, as shown inA
the diagram at right.8
Closes the tutorial andA
returns to Visual Basic.j
A red arrow
points to an instruction
'for you to follow to continue with the A tutorial._
,To return to the Learning Visual Basic Menu,A*press the SPACEBAR. To exit, press ALT+O.
)Press the PAGE DOWN key to continue with
(this lesson. To choose another part of A.Learning Visual Basic or to exit, press ALT+O.
To make the option buttons a
control array, they need to have
the same Name property.
The Cash/Check option button
has the name Option1. We'll set
the Name property of the Charge @
button to Option1.
!That's all that's needed for this
part of the code.
You can run any application
you're working on by choosing
Start from the Run menu or by
clicking the Start button (
) on @
the toolbar. &Options
Payment Method
Cash/Check
Charge
Endif
fraCharge.Visible = False
fraCharge.Visible= True
If Option1(1).Value=True then
&Back
&Instructions
&Menu
&Summary
E&xit Tutorial
Cancel: Esc
&Close Instructions
Next Country
Summary:
dd Watch...
Opens this window.-
Jumps to the SummaryA
for that lesson.
Returns to the Menu.!
Closes the Options A
menu.
One way to avoid problems
caused by mistyped variable
names is to use the
Option
Explicit
statement.
Option Explicit
statement
requires you to declare all@
variables prior to their use.Q
:Despite your best intentions, it's common to make mistakes@
when writing code.
Logic errors
Logic errors can be harder to
#find. When your application runs,
but you get results that aren't
what you expect, you've most @
likely made an error in logic.
With your application running,
you can see how it works.
If Visual Basic detects an error@!in your code, it halts execution.
#Setting breakpoints to temporarily
pause your application so you
can step through your code may @"help you find problems with logic.
Some changes you make to
your application, such as
changing a constant or creating
a new procedure, will require@
you to restart the application.
To continue running your code
from a breakpoint, choose
the Continue command from the
Run menu, or click the Continue@
button on the toolbar.
It could be as simple as a
mistyped or undeclared variable
name, or as complicated as a
statement whose syntax is
correct but whose outcome isn't@
what you expect.
FYou can also display a list of all active procedure calls in the Calls
>dialog box. These are procedures in the application that were
started but not completed.@
5The Debug window allows you to examine code and watch@3expressions. It can be accessed only in break mode.R
When you start the application,
!it will run until it reaches the @
breakpoint.O
The Immediate pane allows
you to execute one line of A
code at a time.@
The Watch pane
shows the values of A
watch expressions.
Debug Window[Form1]j
Visual Basic provides tools to
help you detect these problems
before you compile your @
application.
You can then single-step through
the code by pressing
clicking the Single Step button
on the toolbar to determine @
whether there are any problems.
When you enter code in a Code
window, Visual Basic checks the
"syntax as you move off a line. If
you've made an error, Visual @ Basic displays an error message.
The cursor appears on the line
!of code containing the error, and
an error message is displayed.
You can fix the error and then
!continue running the application.
CallsV
Run-time errors
"To find run-time errors, you need @
to run your application.
Microsoft Visual Basic
nstant Watch...T
.-- mistakes that Visual Basic can detect while
your program is running.
alls...!
ext Statement"
Next Statement
dit Watch...
rocedure Step
iA ngle Step
oggle Breakpoint/
One minute....
...files are being loaded.
Clicking the Options button
opens a menu of different
ways to get around in the
tutorial, as shown inA
the diagram at right.
Division by zero
Click
Form_Click
Counter = 0
Print 1 / Counter
Counter
End SubD
Proc:
Object:
A LoanSheet%
Returns to theA
previous step.
OptionsX
+When you're done reading the Instructions, A$click the Close Instructions button.j
,Click the Menu button ( > ) to return to the
+Learning Visual Basic Menu. To exit, clickA
Options.w
-Click the Next button ( > ) to continue. To
*return to the Menu or exit Learning VisualA
Basic, click Options.
You can have Visual Basic
place the Option Explicit
!statement automatically in every
form and module you create by
choosing Environment from
the Options menu and setting
Require Variable Declaration@
to Yes.
DTo ensure that your application is free of bugs, you need to test it
(in a variety of situations; for example:
4Use large and small values of numbers and strings.
2Often these reveal limitations in the application.
8Ask other people to work with the application. They may
9find problems with its design or discover bugs you didn't
anticipate.
:If your application stores or retrieves data, check to see
*that the information is handled correctly.
+ Test how your application handles errors.@
To insert a breakpoint, position
the cursor on the line of code
!where you want execution to stop.
Then choose Toggle Breakpoint
from the Debug menu, or choose
the Breakpoint button on the @
toolbar.
Compile errorso
3-- mistakes that cause an incorrect result, or that
--@/ prevent your program from running as expected.
Compile errors
Compile errors are caused by
code that violates the rules of
the Visual Basic language. @
These include syntax errors.
Run-time errors
Logic errorsB
@?There are three types of errors you can make when writing code:&
[Form1.frm] ForeColor: 16776960)
A"Form1.ForeColor = RGB(0, 255, 255)
You can either go back and
correct your mistake, press
!and return to the error later, or
press
to get more information@
on the error.$
ear All Breakpoints5
A.How to Use the Learning Visual Basic Tutorial 5
A.How to Use the Learning Visual Basic Tutorial
[Form1.frm] BackColor: 0@
[Form1.frm] BackColor: 0A
[Form1.frm] ForeColor: 16776960
,This lesson discussed three types of errors:
Compile errors
Run-time errors
Logic errors
'It also introduced the debugging tools
available in Visual Basic.
&For more information about debugging,
&see Chapter 9, ''Debugging,'' in the C
Programmer's Guide.;
To go forward in a lesson,A
click the Next button. <
To go backward in a lesson,A
click the Back button. @
--- mistakes caused by incorrectly constructed
code.
(The example files needed for this lesson
)cannot be found. To run this lesson, youA(need to reinstall Learning Visual Basic.
)You can't go back from this point in the
%lesson. To review the lesson, chooseA)Debugging Your Application from the Menu.!
Debugging Your Application
This lesson will cover:
Compile errors
Run-time errors
Logic errors
Visual Basic debugging tools
Expected: variable8
Closes the tutorial andA
returns to Visual Basic.j
A red arrow
points to an instruction
'for you to follow to continue with the A tutorial._
,To return to the Learning Visual Basic Menu,A*press the SPACEBAR. To exit, press ALT+O.
)Press the PAGE DOWN key to continue with
(this lesson. To choose another part of A.Learning Visual Basic or to exit, press ALT+O.
Procedure:
Module:
A LoanSheet
A ShowPmnts
CmdCalcPmts_Click
A SizeCells &Options
&Menu
&Show
&Close
&Back
&Instructions
&Summary
E&xit Tutorial
Cancel: Esc
If (Age > 10 Then,
form1.frm
formchi.frm
Return to &Menu
E&xit Learning VB
code.mak
mdinpad.frm
&Close Instructions
You can create
color schemes
that match
your company'sA
logo.
Catalog
Summary:
Product Order Form
A Inventory
Search
Enter Item Number:
Border Lakes Real Estate
Index
Property Type D
@AYou set the color properties of objects in the Properties window.
Product Sales
Specifications
A Item No.
Bronze
Units Sold
8,200
Units Returned
21,500
Net Unit Sales
-13,300
The property that
you're setting.
Properties that
use colors include
BackColor,
ForeColor,
BorderColor, and A
FillColor.
Item No.
Diametery
BYou can define your own colors and add them to the Color palette.
@0You can have up to 16 custom colors at one time.V
>Similarly, you can use different colors to identify different @
sections of a form.
Units EachH
Visual Basic saves your
custom colors from sessionA
to session. *
Please answer all A
questions.
Product Ordering
Properties
Buyers
Opens this window.-
Jumps to the SummaryA
for that lesson.
Returns to the Menu.!
Closes the Options A
menu.
Sellers
0.375"+
A frame can containA
other controls.X
A picture box or an image
control can display a bitmap,A
an icon, or a metafile.D
Use white to show the fieldsA
in which you enter information.
Quantity
A Cost Each
Total1
Use yellow to showA
the calculated fields.
)Press the PAGE DOWN key to continue with
'this lesson. To choose another part ofA.Learning Visual Basic or to exit, press ALT+O.
Bin No.
Length
HEX7782A
150,500
Auditor
Log No.
Wyatt
5/4/91
WA-5B-91>
The blue section shows A
information about the product.:
The red section showsA
information about the audit.
=As you design your forms, try to avoid using too many colors.
>You'll have better results if you pick one group of colors and@
stick to them.
Production Outline
Length
Diameter
HEX7782A
Material
1.25"
Material
Price Range
Item No.
CYou can also use Visual Basic code to change the color of an object
0while your application is running. For example:
<You can change the color of a field as soon as a user moves
to that field.K
(In this form, one color is used for the A
background for all fields.
1.25"
0.375"
Clicking the Options button
opens a menu of different
ways to get around in the
tutorial, as shown inA
the diagram at right.
Bronzep
)Here, a different color is used for each
'field. Notice how the form appears tooA
busy and distracting.
?When designing applications that rely extensively on color, you
@may find it helpful to use a color guide or work with a designer@3to make the best use of color in your applications.
Buyer Survey
Community:
Residential Properties
CondominiumM
A very small application
created in A
Visual Basic 2.0.
&This lesson discussed using color and
+graphics in your Visual Basic applications.
%For more information on graphics, see
#Chapter 15, ''Creating Graphics for
Applications,'' in the
Programmer's Guide.
Undeveloped Land
A House
AUsing color and graphics effectively is an art. In the following
?screens, we offer some basic tips on the different ways you can@
enhance your applications.m
=You can design custom command buttons for a form by attaching@+code to an image control or a picture box.
John and Jane Homebuyer
Border Lakes
$50,000
Border Lakes
txtSales_Change
If
txtSales.Text < 0
txtSales.ForeColor =
RGB(
255,0,0
Else
txtSales.ForeColor =
0,0,0
End If
End Subt
This application
displays a message
and draws a box around
a field if a user leaves A
that field empty.
Client Name:D
The Visual Basic language
can be used to draw otherA
shapes.R
MWith Visual Basic, you can easily add color and graphics to an application. @
Product SalesO
>You can use Visual Basic code to display graphics in response @
to an event.
PAN3352AI
Lines and shapes can be
added to forms toA
emphasize information.5
You can create
arcs using theA
Circle method.G
You can create temporary
visual effects with the A
Line method.+
The object that A
you're working on.j
CAdding color to your forms and controls can make your applications @"more attractive and easier to use.A
You can use colors to
emphasize important A
information.<
You choose a color fromA
the drop-down Color palette.
Using Color and Graphics
Form1 B
A DrawWidth
A BackColor
BorderStyle
Caption
ClipControls
ControlBox
DrawMode
A DrawStyle
&H000040C0&
2 - Sizable
Form1
13 - Copy Pen
A 0 - Solid
Properties%
Returns to theA
previous step.
OptionsX
+When you're done reading the Instructions, A$click the Close Instructions button.w
-Click the Next button ( > ) to continue. To
*return to the Menu or exit Learning VisualA
Basic, click Options.
JGraphics methods in the Visual Basic language also let you create graphics
Hin your application. Creating graphics with graphics methods is done in
Fcode, so these images appear on your form only when the application is@
running.b
5You can make your forms easier to use by applying the@(same color to similar types of fields. 5
A.How to Use the Learning Visual Basic Tutorial 8
Closes the tutorial andA
returns to Visual Basic.5
A.How to Use the Learning Visual Basic Tutorial \
txtItemNo_GotFocus
txtItemNo.BackColor = &HFFFF&A
End Sub
CYou can also use Visual Basic code to change the color of an object
0while your application is running. For example:
<You can change the color of a field as soon as a user moves
to that field.
<You can control the color of a value, depending upon whether
@#that value is positive or negative.
Threads/in.
Each button on this form is
an image control. When a
user clicks a picture,
Visual Basic runs the code A
attached to that control.d
The Define Colors button
displays a dialog box
that allows you to select A
custom colors.
Johnson
Nut and Bolt, Inc.%
Product CatalogA
January, 1993;
To go forward in a lesson,A
click the Next button. <
To go backward in a lesson,A
click the Back button. O
@LGraphics can increase the usefulness of and add visual impact to your forms.
This lesson covers:
Using graphics
Using colors
&Changing graphics and colors with code
@(Designing forms with graphics and colorsj
A red arrow
points to an instruction
'for you to follow to continue with the A tutorial.
About this Application &Options
&Menu
Default
Custom Colors >>
Define Colors...
Search
Index
&Back
&Instructions
&Summary
E&xit Tutorial
Cancel: Esc
&Close Instructions
p u p
wwwwwwwwpwwwwwwwww
wwwwwwwwp
wwwwwwww
wwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwww
;;;30
wwwwwwwp
wwwwwwp
wwwwwwwp
wwwwwwp
wwwwwwwp
wwwwwwp
wwwwwww
wwwwwww
wwwwwwwp
wwwwwww
wwwwwww
wwwwwwp
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwp
wwwwwwp
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwp
wwwwwwwwp
wwwwwwx