home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CICA 1993 August
/
CICA.cdr
/
unzipped
/
programr
/
vbasic
/
vbprimer
/
vb.le_
/
vb.bin
(
.txt
)
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
Microsoft Lesson
|
1992-12-15
|
209.5 KB
|
1,617 lines
Out of Memory xxx
File Missing
Unrecognized Error
Microsoft CBT
&Instructions
&Back
&Menu
&Summary
E&xit Tutorial
Cancel: Esc
Options
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.&
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
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwww
wwwwwww
wwwxw
wwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwww
wwwwwww
wwwww
UUUUUUUUUUUWx
UUUUUUUUUUUWw
UUUUUUUUUUUUx
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.N
ile
dit
ode
un
indow
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. &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
www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wwwwwwwwwwwwwwwwww
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
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