Sie sind auf Seite 1von 37

Microsoft Visual Basic 2010:

Reloaded
Fourth Edition
Chapter One
An Introduction to Visual Basic 2010
2009 Pearson Education, Inc. All rights resered.
2
!erie"
#
$hat Is a %o&'uter(
#
Machine, Asse&)l* and +igh,-eel -anguages
#
Visual Basic . !ther +igh,-eel -anguages
#
!)/ect 0echnolog*
#
0he Internet and the $orld $ide $e)
#
Introduction to Microsoft .1E0
#
-anguage and 2*nta3
#
Visual 2tudio 2010 I4E
#
2olutions and Pro/ects
#
%reating a 1e" Pro/ect
#
E3a&'les
2009 Pearson Education, Inc. All rights resered.
5
$hat Is a %o&'uter(
#
A computer is a deice that can 'erfor&
calculations and &a6e logical decisions &uch
faster than hu&ans can.
#
%o&'uters 'rocess data, using sets of
instructions called computer programs.
7
0hese 'rogra&s guide co&'uters through orderl* sets of
actions that are s'ecified )* 'eo'le 6no"n as computer
programmers.
2009 Pearson Education, Inc. All rights resered.
8
$hat Is a %o&'uter(
#
A co&'uter is co&'osed of arious deices
6no"n as hardware:
7
6e*)oard
7
screen
7
&ouse
7
hard dries
7
&e&or*
7
4V4 dries
7
'rinter
7
'rocessing units
#
0he 'rogra&s that run on a co&'uter are referred to
as software.
2009 Pearson Education, Inc. All rights resered.
9
%o&'uter %o&'onents
%o&'uters can )e thought of as )eing diided
into si3 units:
#
Input unit: 0his :receiing; section of the
co&'uter o)tains infor&ation fro& input devices.
7
In'ut can co&e fro& deices such as the 6e*)oard and
the &ouse.
#
Output unit: 0his :shi''ing; section of the
co&'uter ta6es infor&ation that the co&'uter has
'rocessed and 'laces it on arious output devices.
7
!ut'ut can )e dis'la*ed on screens, 'rinted on 'a'er,
'la*ed on audio<ideo deices, and trans&itted oer the
Internet.
2009 Pearson Education, Inc. All rights resered.
=
%o&'uter %o&'onents
#
Memory unit: 0his :"arehouse; section of the
co&'uter stores data "hile an a''lication is
running. Its infor&ation is i&&ediatel* aaila)le for
'rocessing.
7 0o )e e3ecuted, co&'uter 'rogra&s &ust )e in &e&or*.
7 0he &e&or* unit retains infor&ation until it can )e sent to
out'ut deices.
7 !ften, the &e&or* unit is called either memory or primary
memory.
7 Random-access memory (RAM) is an e3a&'le of 'ri&ar*
&e&or*.
7 Pri&ar* &e&or* is usuall* volatile, "hich &eans that it is
erased "hen the &achine is 'o"ered off.
2009 Pearson Education, Inc. All rights resered.
>
%o&'uter %o&'onents
#
Central processing unit (CP): 0he %P? su'erises
the o'eration of the other sections.
#
Arithmetic and logic unit (A!): 0he A-? @a 'art of the
%P?A 'erfor&s calculations and &a6es decisions.
#
"econdary storage unit: 0his unit is the :"arehousing;
section of the co&'uter.
7 4eices such as hard dries, %4,R!M dries, 4V4 dries,
and ?2B &e&or* stic6s are secondar* storage units.
7 0hese nor&all* hold 'rogra&s or data that other units are not
actiel* )eing used.
7 0he co&'uter can retriee this infor&ation "hen it is needed
later in ti&e. 2econdar* storage is nonolatile.
7 Infor&ation in secondar* storage ta6es &uch longer to access
than infor&ation in 'ri&ar* &e&or*.
2009 Pearson Education, Inc. All rights resered.
B
Machine, Asse&)l* and +igh,-eel -anguages
#
Progra&&ers "rite instructions in 'rogra&&ing
languages. 2o&e of these are directl*
understanda)le )* co&'uters, and others reCuire
inter&ediate translation ste's.
#
%o&'uter languages that are in use toda* can )e
diided into three general t*'es:
7
&achine languages
7
asse&)l* languages
7
high,leel languages
2009 Pearson Education, Inc. All rights resered.
9
Machine, Asse&)l* and +igh,-eel -anguages
#
A co&'uter can directl* understand onl* its o"n
machine language.
#
As the :natural language; of a 'articular co&'uter,
&achine language is defined )* the co&'uterDs
hard"are design. Machine languages are &achine
de'endent.
#
Machine languages generall* consist of strea&s of
nu&)ers @ulti&atel* reduced to 1s and 0s in the
)inar* nu&)er s*ste&A.
2009 Pearson Education, Inc. All rights resered.
10
Machine, Asse&)l* and +igh,-eel -anguages
#
0he follo"ing section of a &achine,language
'rogra& de&onstrates the inco&'rehensi)ilit* of
&achine language to hu&ans:
+1300042774
+1400593419
+1200274027
#
Machine,language 'rogra&&ing 'roed to )e
slo" and error 'rone.
2009 Pearson Education, Inc. All rights resered.
11
Machine, Asse&)l* and +igh,-eel -anguages
#
Progra&&ers )egan using English,li6e
a))reiations to re'resent the co&'uterDs )asic
o'erations.
#
0hese a))reiations for&ed the )asis of
assem#ly languages.
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
2009 Pearson Education, Inc. All rights resered.
12
Machine, Asse&)l* and +igh,-eel -anguages
#
$ranslator programs called assem#lers
conert asse&)l*,language 'rogra&s to
&achine language.
#
Although it is clearer to hu&ans, co&'uters
cannot understand asse&)l*,language code
until it is translated into &achine language.
#
Asse&)l* languages still reCuire &an*
instructions to acco&'lish een the si&'lest
tas6s.
2009 Pearson Education, Inc. All rights resered.
15
Machine, Asse&)l* and +igh,-eel -anguages
#
0o s'eed u' the 'rogra&&ing 'rocess,
high-level languages "ere deelo'ed.
#
Progra&s called compilers conert high,leel,
language 'rogra&s into &achine language.
#
+igh,leel languages loo6 al&ost li6e eer*da*
English and contain co&&on &athe&atical
notations.
grossPay = basPay + o!rT"#Pay
#
Visual Basic is one of the "orldDs &ost 'o'ular
high,leel 'rogra&&ing languages.
2009 Pearson Education, Inc. All rights resered.
18
Visual Basic
#
Visual Basic eoled fro& %A"IC @BeginnerDs
All,'ur'ose 2*&)olic Instruction %odeA, "hich
"as deelo'ed as a language for "riting si&'le
'rogra&s Cuic6l* and easil*.
#
$hen Bill Eates founded Microsoft %or'oration
in the 19>0s, he i&'le&ented BA2I% on seeral
earl* 'ersonal co&'uters.
2009 Pearson Education, Inc. All rights resered.
19
Visual Basic
#
In the late 19B0s and the earl* 1990s, Microsoft
deelo'ed the Microsoft
F
$indo"s
F
graphical
user interface (&I).
#
'isual %asic "as introduced )* Microsoft in 1991
to &a6e 'rogra&&ing $indo"s a''lications
easier.
2009 Pearson Education, Inc. All rights resered.
1=
Visual Basic
#
Visual Basic is a so,called o)/ect,oriented,
eent,drien isual 'rogra&&ing language.
#
Progra&s are created "ith the use of a soft"are
tool called an Integrated (evelopment
)nvironment (I()).
#
0he latest ersions of Visual Basic are full* o)/ect
oriented and res'ond to user,initiated events such
as &ouse clic6s, 6e*stro6es and ti&ers.
#
In Visual 2tudio, it is conenient to &a6e 'rogra&s
)* dragging and dro''ing 'redefined o)/ects li6e
)uttons and te3t)o3es.
2009 Pearson Education, Inc. All rights resered.
1>
Visual Basic
#
Microsoft introduced its .1E0 strateg* in 2000.
#
0he *+)$ platform allo"s a''lications to )e
distri)uted to a ariet* of deices.
#
2oft"are co&'onents created in different .1E0
'rogra&&ing languages can co&&unicate "ith
one another.
2009 Pearson Education, Inc. All rights resered.
1B
!ther +igh,-eel -anguages
#
Although hundreds of high,leel languages hae
)een deelo'ed, onl* a fe" hae achieed )road
acce'tance.
#
IBM %or'oration deelo'ed ,ortran in the
&id,1990s to create scientific and engineering
a''lications.
#
CO%O! "as deelo'ed in the late 1990s )* a
grou' of co&'uter &anufacturers. %!B!- is
used 'ri&aril* for )usiness a''lications that
reCuire the &ani'ulation of large a&ounts of data.
2009 Pearson Education, Inc. All rights resered.
19
!ther +igh,-eel -anguages
#
0he % language gained "ides'read recognition as
a deelo'&ent language for the ?1IG o'erating
s*ste&.
#
%HH "as deelo'ed )* B/arne 2troustru' in the
earl* 19B0s at Bell -a)oratories. %HH 'roides
ca'a)ilities for o#-ect-oriented programming
(OOP).
7
O#-ects are reusa)le soft"are components that
&odel ite&s in the real "orld.
7
!)/ect,oriented 'rogra&s are easier to understand,
correct and &odif*.
2009 Pearson Education, Inc. All rights resered.
20
!ther +igh,-eel -anguages
#
4eelo'ers use .ava to create "e) 'ages "ith
d*na&ic content, to )uild large,scale enter'rise
a''lications, to enhance the functionalit* of "e)
serers, and to 'roide a''lications for
consu&er deices.
#
In 2000, Microsoft announced C/. 0he %I
'rogra&&ing language "as designed
s'ecificall* for the .1E0 'latfor&. -i6e Visual
Basic, %I is o)/ect oriented and has access
to .1E0Ds li)rar*.
2009 Pearson Education, Inc. All rights resered.
21
!)/ect 0echnolog*
#
O#-ect technology is a 'ac6aging sche&e for
creating &eaningful soft"are units.
#
Al&ost an* noun can )e reasona)l* re'resented
as a soft"are o)/ect.
#
!)/ects:
7
hae properties such as color, siJe and "eight
7
'erfor& actions such as &oing, slee'ing or dra"ing
#
A class s'ecifies the general for&at of its
o)/ects, and the 'ro'erties and actions aaila)le
to an o)/ect de'end on its class.
2009 Pearson Education, Inc. All rights resered.
22
!)/ect 0echnolog*
#
Procedural programming languages focused on
actions @er)sA rather than o)/ects @nounsA.
#
!)/ect,oriented languages &ore naturall* reflects the
"a* in "hich "e 'erceie the "orld.
#
0his has resulted in significant 'roductiit* gains.
7
Pro'erl* designed classes can )e reused on future
'ro/ects
7
?sing li)raries of classes reduces the a&ount of effort
reCuired to i&'le&ent ne" s*ste&s
7
0he 'roduction of soft"are is &ore understanda)le
)ecause it is )etter organiJed and has fe"er &aintenance
reCuire&ents.
2009 Pearson Education, Inc. All rights resered.
25
!)/ect 0echnolog*
#
Instead of "orr*ing a)out the details of ho"
o)/ects are i&'le&ented, *ou can focus on the
)ehaiors and interactions of o)/ects.
#
Visual Basic is one of the "orldDs &ost "idel*
used o)/ect,oriented languages.
2009 Pearson Education, Inc. All rights resered.
28
0he Internet and the $orld $ide $e)
#
In the late 19=0s, ARPA rolled out 'lans to
net"or6 the &ain co&'uter s*ste&s of ARPA,
funded uniersities and research institutions.
#
0his )eca&e 6no"n as the ARPAnet, the
grand'arent of toda*Ds Internet.
#
Its &ain )enefit 'roed to )e the ca'a)ilit* for
Cuic6 and eas* co&&unication ia "hat ca&e to
)e 6no"n as electronic mail (e-mail).
2009 Pearson Education, Inc. All rights resered.
E3a&'les of Progra&&ing -anguages
#
%: fast, efficient code
#
Kaa: 'latfor& inde'endence
#
BA2I%: ease of use
#
Visual Basic: user interface design using for&s
#
Perl: te3t &ani'ulation
29
2009 Pearson Education, Inc. All rights resered.
Visual Basic.1E0 s*nta3
If 3L9 0hen
MessageBo3.2ho"@MI a& greater than 9.MA
Else
MessageBo3.2ho" @MI a& not greater than 9.MA
End If
2=
2009 Pearson Education, Inc. All rights resered.
%I 2*nta3
if @3L9A
N
MessageBo3.2ho" @MI a& greater than 9.MAO
P
else
N
MessageBo3.2ho" @MI a& not greater than 9.MAO
P
2>
2009 Pearson Education, Inc. All rights resered.
-earning a Progra&&ing -anguage
#
2*nta3
#
2tructure
#
Rules
#
Punctuation
#
Resered $ords @6e*"ordsA eg. If, Else
#
Visual Basic.1E0 is 1!0 case sensitie.
M*%ase is the sa&e as &*%ase and MQ%A2E.
#
%o&&ent lines start "ith an a'ostro'he @RA
2B
2009 Pearson Education, Inc. All rights resered.
29
#
'isual "tudio
0
1232 is MicrosoftDs integrated
development environment (I()) for creating,
running and de)ugging a''lications.
#
0he I4E allo"s *ou to create a''lications )*
dragging and dro''ing e3isting )uilding )loc6s
into 'lace.
#
0his techniCue is called visual programming.
#
It is a Ra'id A''lication 4eelo'&ent @RA4A tool
)ecause it is focused on 'roductiit*.
Visual 2tudio 2010 I4E
2009 Pearson Education, Inc. All rights resered.
Visual 2tudio 2010 -anguages
#
Visual Basic.1E0
#
%I @'ronounced %,2har'A
#
KI @'ronounced K,2har'A
#
%HH @'ronounced % 'lus 'lusA
#
A2P.1E0 @"e) 'age creationA
50
2009 Pearson Education, Inc. All rights resered.
Visual Basic 2010 E3'ress
#
Visual Basic E3'ress is a co&'act deelo'&ent
eniron&ent for creating Visual Basic.1E0
a''lications.
#
%an create different t*'es of a''lications
$indo"s A''lications @$indo"s Sor&s or $PS A''licationA
%onsole A''lications
Reusa)le co&'onents or class li)raries
#
%annot )uild "e) sites or "e) serices "ith the
Visual Basic E3'ress Edition.
51
2009 Pearson Education, Inc. All rights resered.
2o&e Adantages of Visual Basic 2010 E3'ress I4E
#
Ereatl* reduces a&ount of code *ou &ust "rite
#
Auto&aticall* colors code de'ending "hat it is
%o&&ents are Ereen
Te*"ords are Blue
#
!rganiJes code in se'arate files
#
Intelli2ense
%ode 2ni''ets
#
Real,ti&e co&'iler feed)ac6
Blue sCuiggle under code indicates an error
Ereen sCuiggle under code indicates a 'ossi)le error
52
2009 Pearson Education, Inc. All rights resered.
2olutions and Pro/ects
#
Visual Basic organiJes a''lications into solutions
and pro-ects.
#
"olutions contain one or &ore 'ro/ects.
#
A pro-ect is a grou' of related files, such as code
and i&ages that &ight &a6e u' a 'rogra&.
55
2009 Pearson Education, Inc. All rights resered.
2olutions, Pro/ects, and Siles
2009 Pearson Education, Inc. All rights resered.
%reating a 1e" Pro/ect
#
2elect either File > New Project, "hich
creates a ne" 'ro/ect, or File > Open
Project, "hich o'ens an e3isting 'ro/ect.

#
Sro& the Start Page, under the Recent
Projects section, clic6 the lin6 Create:
Project or Open: Project.
#
%lic6 either the New Project B$%%o& or the
Open File B$%%o&.
59
2009 Pearson Education, Inc. All rights resered.
$or6ing $ith a Pro/ect
#
0he Solution Explorer "indo" dis'la*s a list of
the files in a 'ro/ect and the 'ro/ects in a solution.
#
0he Properties "indo" dis'la*s an o)/ectDs
attri)utes, such as its siJe, color and 'osition. 0he
Properties "indo" allo"s *ou to set o)/ect
'ro'erties isuall* "ithout "riting code.
#
?sing isual 'rogra&&ing, *ou can :drag and
dro'; controls onto the Sor& fro& the Toolbox.
5=
Properties icon O#-ect %rowser icon
$ool#o4 icon "olution )4plorer icon
2009 Pearson Education, Inc. All rights resered.
5>
,igure 1*11 5 Properties "indo" dis'la*ing a 'or#Ds 'ro'erties.
Objects
name
(Form1)
Objects class
(System.Windows.Forms.Form)
Down arrow for selecting Form
or control objects
Items that have been
changed from their default
values (by the user or by Visual
Studio) are listed in bold
Proerty values
(right column)
Proerties
(left column)
Descrition of
selected roerty
4esign category
Selected roerty
!lhabetical icon
"ategori#ed icon
"omonent object bo$
Pro'erties $indo"

Das könnte Ihnen auch gefallen