Copyright 2011 Pearson Addison-Wesley
Addison Wesley
is an imprint of
2011 Pearson Addison-Wesley. All rights reserved.
Chapter 1
Introduction to
Programming and Visual
Basic
Copyright 2011 Pearson Addison-Wesley
Addison Wesley
is an imprint of
2011 Pearson Addison-Wesley. All rights reserved.
Section 1.3
More about controls and
programming
As a Visual Basic programmer, you must
design and create an
applications !"I elements #$orms and
other controls% and the
programming statements that respond to
and&or per$orm actions
#e'ent handlers%.
Copyright 2011 Pearson Addison-Wesley
Visual Basic Controls
As a (indo)s user youre already $amiliar
)ith many Visual Basic controls*
+abel , displays te-t the user cannot change
.e-tBo- , allo)s the user to enter te-t
Button / per$orms an action )hen clic0ed
1adioButton , A round button that is selected or
deselected )ith a mouse clic0
Chec0Bo- / A bo- that is chec0ed or unchec0ed
)ith a mouse clic0
2orm , A )indo) that contains these controls
.utorial 1,3 demonstrates these controls
Chapter 1 , Slide 3
Copyright 2011 Pearson Addison-Wesley
.utorial 1,3, Visual Basic
Controls
Chapter 1 , Slide 3
Copyright 2011 Pearson Addison-Wesley
.he 4ame Property
All controls ha'e properties
5ach property has a 'alue #or 'alues%
4ot all properties deal )ith appearance
.he name property establishes a means $or
the program to re$er to that control
Controls are assigned relati'ely meaningless
names )hen created
Programmers usually change these names to
something more meaning$ul
Chapter 1 , Slide 6
Copyright 2011 Pearson Addison-Wesley
5-amples o$ 4ames
.he +abel controls use the de$ault names
#+abel1, etc.%
.e-t bo-es, buttons, and the !ross Pay label
play an acti'e role in the program and ha'e
been changed
btnCal!rossPay btnClose
t"t#o$rsWor%ed
t"tPay&ate
lbl!rossPay
'abel1
'abel2
'abel(
)orm1
Chapter 1 , Slide 7
Copyright 2011 Pearson Addison-Wesley
4aming Con'entions
Control names must start )ith a letter
1emaining characters may be letters, digits, or
underscore
1st 3 lo)ercase letters indicate the type o$
control
t-t8 $or .e-t Bo-es
lbl8 $or +abels
btn8 $or Buttons
A$ter that, capitali9e the $irst letter o$ each
)ord
t-t:ours(or0ed is clearer than
t-thours)or0ed
Chapter 1 , Slide ;
Copyright 2011 Pearson Addison-Wesley
Addison Wesley
is an imprint of
2011 Pearson Addison-Wesley. All rights reserved.
Section 1.3
.he Programming Process
.he programming process consists o$
se'eral steps, )hich include
designing, creating, testing, and debugging
acti'ities.
Copyright 2011 Pearson Addison-Wesley
Step 1 o$ <e'eloping an Application
Clearly de$ine )hat the program is to do
2or e-ample, the (age Calculator program*
Purpose* .o calculate the users gross pay
Input* 4umber o$ hours )or0ed, hourly pay rate
Process* Multiply number o$ hours )or0ed by
hourly pay rate #result is the users gross pay%
=utput* <isplay a message indicating the users
gross pay
Chapter 1 , Slide >
Copyright 2011 Pearson Addison-Wesley
Step ? o$ <e'eloping an Application
Visuali9e the application running on the
computer and design its user inter$ace
Chapter 1 , Slide
1@
Copyright 2011 Pearson Addison-Wesley
Step 3 o$ <e'eloping an Application
<etermine the controls needed
Type Name Description
.e-tBo- t-t:ours(or0ed Allo)s the user to enter the number o$ hours )or0ed.
.e-tBo- t-tPay1ate Allo)s the user to enter the hourly pay rate
+abel lbl!rossPay <isplays the gross pay, a$ter the btnCalc!rossPay
button has been clic0ed
Button btnCalc!rossPay (hen clic0ed, multiplies the number o$ hours )or0ed
by the hourly pay rate
Button btnClose (hen clic0ed, terminates the application
+abel #de$ault% <escription $or 4umber o$ :ours (or0ed .e-tBo-
+abel #de$ault% <escription $or :ourly Pay 1ate .e-tBo-
+abel #de$ault% <escription $or !ross Pay 5arned +abel
2orm #de$ault% A $orm to hold these controls
Chapter 1 , Slide
11
Copyright 2011 Pearson Addison-Wesley
Step 3 o$ <e'eloping an Application
<e$ine the 'alues o$ each controls rele'ant
properties
Control Type Control Name Text
2orm #<e$ault% A(age CalculatorA
+abel #<e$ault% A4umber o$ :ours (or0edA
+abel #<e$ault% A:ourly Pay 1ateA
+abel #<e$ault% A!ross Pay 5arnedA
+abel lbl!rossPay AB@.@@A
.e-tBo- t-t:ours(or0ed AA
.e-tBo- t-tPay1ate AA
Button btnCalc!rossPay ACalculate !ross PayA
Button btnClose ACloseA
Chapter 1 , Slide
1?
Copyright 2011 Pearson Addison-Wesley
Step 6 o$ <e'eloping an Application
<etermine the e'ent handlers and other code
needed $or each control
Method Description
btnCalc!rossPayCClic0 Multiplies hours )or0ed by hourly pay rate
.hese 'alues are entered into the
t-t:ours(or0ed and t-tPay1ate .e-tBo-es
1esult is stored in lbl!rossPay .e-t property
btnCloseCClic0 .erminates the application
Chapter 1 , Slide
13
Copyright 2011 Pearson Addison-Wesley
Step 7 o$ <e'eloping an Application
Create a $lo)chart or pseudocode 'ersion o$
the code
A $lo)chart is a diagram that graphically depicts the $lo)
o$ a method
Pseudocode is a cross bet)een human language and a
programming language
Chapter 1 , Slide
13
Copyright 2011 Pearson Addison-Wesley
Step ; o$ <e'eloping an Application
Chec0 the code $or errors*
1ead the $lo)chart and&or pseudocode
Step through each operation as though you are
the computer
"se a piece o$ paper to Dot do)n the 'alues o$
'ariables and properties as they change
Veri$y that the e-pected results are achie'ed
Chapter 1 , Slide
16
Copyright 2011 Pearson Addison-Wesley
Step E o$ <e'eloping an Application
"se Visual Basic to create the $orms and other
controls identi$ied in step 3
.his is the $irst use o$ Visual Basic, all o$ the
pre'ious steps ha'e Dust been on paper
In this step you de'elop the portion o$ the
application the user )ill see
Chapter 1 , Slide
17
Copyright 2011 Pearson Addison-Wesley
Step > o$ <e'eloping an Application
"se the $lo)charts or pseudocode $rom step 7
to )rite the actual code
.his is the second step on the computer
In this step you de'elop the methods behind the
clic0 e'ent $or each button
"nli0e the $orm de'eloped on step E, this portion
o$ the application is in'isible to the user
Chapter 1 , Slide
1;
Copyright 2011 Pearson Addison-Wesley
Step 1@ o$ <e'eloping an
Application
Attempt to run the application , $ind synta-
errors
Correct any synta- errors $ound
Synta- errors are the incorrect use o$ an element
o$ the programming language
1epeat this step as many times as needed
All synta- errors must be remo'ed be$ore Visual
Basic )ill create a program that actually runs
Chapter 1 , Slide
1E
Copyright 2011 Pearson Addison-Wesley
Step 11 o$ <e'eloping an
Application
1un the application using test data as input
1un the program )ith a 'ariety o$ test data
Chec0 the results to be sure that they are correct
Incorrect results are re$erred to as a runtime error
Correct any runtime errors $ound
1epeat this step as many times as necessary
Chapter 1 , Slide
1>
Copyright 2011 Pearson Addison-Wesley
Addison Wesley
is an imprint of
2011 Pearson Addison-Wesley. All rights reserved.
Section 1.6
Visual Studio and Visual Basic 5-press 5dition
#the Visual Basic 5n'ironment%
Visual Studio and Visual Basic 5-press
5dition consist o$ tools that
you use to build Visual Basic applications.
.he $irst step in using
Visual Basic is learning about these tools.
Copyright 2011 Pearson Addison-Wesley
.he Visual Studio I<5
Visual Studio is an integrated de'elopment
en'ironment, o$ten abbre'iated as I<5
Pro'ides e'erything needed to create, test, and
debug so$t)are including*
.he Visual Basic language
2orm design tools to create the user inter$ace
<ebugging tools to help $ind and correct
programming errors
Visual Studio supports other languages beside
Visual Basic such as CFF and CG
Chapter 1 , Slide
?1
Copyright 2011 Pearson Addison-Wesley
.he Visual Basic 5n'ironment
.utorial 1,3 introduces elements o$ the I<5*
Customi9ing the I<5
<esign )indo) / a place to design and create a
$orm
Solution 5-plorer )indo) / sho)s $iles in the
solution
Properties )indo) / modi$y properties o$ an
obDect
<ynamic :elp )indo) / a handy re$erence tool
.oolbar / contains icons $or $reHuently used
$unctions
.oolbo- )indo) / obDects used in $orm design
.ooltips / a short description o$ buttons purpose
Chapter 1 , Slide
??