Vb 01edited

download Vb 01edited

of 37

Transcript of Vb 01edited

  • 8/10/2019 Vb 01edited

    1/37

    Microsoft Visual Basic 2010:

    Reloaded

    Fourth Edition

    Chapter OneAn Introduction to Visual Basic 2010

  • 8/10/2019 Vb 01edited

    2/37

    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 echnolog*# he Internet and the $orld $ide $e)

    # Introduction to Microsoft .E

    # -anguage and *nta3

    # Visual tudio 2010 I4E

    # olutions and Pro/ects

    # %reating a e" Pro/ect

    # E3a&'les

  • 8/10/2019 Vb 01edited

    3/37

    2009 Pearson Education, Inc. All rights resered.

    5

    $hat Is a %o&'uter(

    #A computeris 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 hese 'rogra&s guide co&'uters through orderl* sets of

    actions that are s'ecified )* 'eo'le 6no"n as computer

    programmers.

  • 8/10/2019 Vb 01edited

    4/37

    2009 Pearson Education, Inc. All rights resered.

    8

    $hat Is a %o&'uter(

    # A co&'uter is co&'osed of arious deices6no"n as hardware:

    7 6e*)oard

    7 screen

    7 &ouse

    7 hard dries

    7 &e&or*

    7 4V4 dries

    7 'rinter

    7 'rocessing units

    # he 'rogra&s that run on a co&'uter are referred to

    as software.

  • 8/10/2019 Vb 01edited

    5/37

    2009 Pearson Education, Inc. All rights resered.

    %o&'uter %o&'onents

    %o&'uters can )e thought of as )eing diidedinto si3 units:

    # Input unit: his 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: his shi''ing; section of theco&'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

  • 8/10/2019 Vb 01edited

    6/37

    2009 Pearson Education, Inc. All rights resered.

    =

    %o&'uter %o&'onents

    # Memory unit: his "arehouse; section of theco&'uter stores data "hile an a''lication is

    running. Its infor&ation is i&&ediatel* aaila)le for

    'rocessing.

    7 o )e e3ecuted, co&'uter 'rogra&s &ust )e in &e&or*.7 he &e&or* unit retains infor&ation until it can )e sent to

    out'ut deices.

    7 !ften, the &e&or* unit is called either memoryorprimary

    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.

  • 8/10/2019 Vb 01edited

    7/372009 Pearson Education, Inc. All rights resered.

    >

    %o&'uter %o&'onents

    # Central processing unit (CP): he %P? su'erisesthe o'eration of the other sections.

    # Arithmetic and logic unit (A!): he A-? @a 'art of the%P? 'erfor&s calculations and &a6es decisions.

    # "econdary storage unit: his unit is the "arehousing;section of the co&'uter.

    7 4eices such as hard dries, %4R!M dries, 4V4 dries,and ?B &e&or* stic6s are secondar* storage units.

    7 hese nor&all* hold 'rogra&s or data that other units are not

    actiel* )eing used.

    7 he co&'uter can retriee this infor&ation "hen it is neededlater in ti&e. econdar* storage is nonolatile.

    7 Infor&ation in secondar* storage ta6es &uch longer to accessthan infor&ation in 'ri&ar* &e&or*.

  • 8/10/2019 Vb 01edited

    8/372009 Pearson Education, Inc. All rights resered.

    Machine, Asse&)l* and +igh-eel -anguages

    # Progra&&ers "rite instructions in 'rogra&&inglanguages. o&e of these are directl*understanda)le )* co&'uters, and others reCuireinter&ediate translation ste's.

    # %o&'uter languages that are in use toda* can )ediided into three general t*'es:

    7 &achine languages

    7 asse&)l* languages

    7 highleel languages

  • 8/10/2019 Vb 01edited

    9/372009 Pearson Education, Inc. All rights resered.

    9

    Machine, Asse&)l* and +igh-eel -anguages

    # A co&'uter can directl* understand onl* its o"nmachine language.

    # As the natural language; of a 'articular co&'uter,&achine language is defined )* the co&'uterDs

    hard"are design. Machine languages are &achinede'endent.

    # Machine languages generall* consist of strea&s ofnu&)ers @ulti&atel* reduced to 1s and 0s in the

    )inar* nu&)er s*ste&.

  • 8/10/2019 Vb 01edited

    10/372009 Pearson Education, Inc. All rights resered.

    10

    Machine, Asse&)l* and +igh-eel -anguages

    # he follo"ing section of a &achinelanguage'rogra& de&onstrates the inco&'rehensi)ilit* of

    &achine language to hu&ans:

    +1300042774

    +1400593419+1200274027

    # Machinelanguage 'rogra&&ing 'roed to )eslo" and error 'rone.

  • 8/10/2019 Vb 01edited

    11/37

  • 8/10/2019 Vb 01edited

    12/372009 Pearson Education, Inc. All rights resered.

    12

    Machine, Asse&)l* and +igh-eel -anguages

    # $ranslator programscalled assem#lersconert 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&'lesttas6s.

  • 8/10/2019 Vb 01edited

    13/372009 Pearson Education, Inc. All rights resered.

    15

    Machine, Asse&)l* and +igh-eel -anguages

    # o s'eed u' the 'rogra&&ing 'rocess,high-level languages"ere deelo'ed.

    # Progra&s called compilersconert highleel

    language 'rogra&s into &achine language.

    # +ighleel 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

    highleel 'rogra&&ing languages.

    18

  • 8/10/2019 Vb 01edited

    14/372009 Pearson Education, Inc. All rights resered.

    18

    Visual Basic

    # Visual Basic eoled fro& %A"IC@BeginnerDsAll'ur'ose *&)olic Instruction %ode, "hich

    "as deelo'ed as a language for "riting si&'le

    'rogra&s Cuic6l* and easil*.

    # $hen Bill ates founded Microsoft %or'oration

    in the 19>0s, he i&'le&ented BAI% on seeral

    earl* 'ersonal co&'uters.

    1

  • 8/10/2019 Vb 01edited

    15/372009 Pearson Education, Inc. All rights resered.

    1

    Visual Basic

    # In the late 190s and the earl* 1990s, Microsoftdeelo'ed the MicrosoftF$indo"sFgraphical

    user interface (&I).

    # 'isual %asic"as introduced )* Microsoft in 1991

    to &a6e 'rogra&&ing $indo"s a''lications

    easier.

    1=

  • 8/10/2019 Vb 01edited

    16/372009 Pearson Education, Inc. All rights resered.

    1=

    Visual Basic

    # Visual Basic is a socalled o)/ectoriented,eentdrien isual 'rogra&&ing language.

    # Progra&s are created "ith the use of a soft"are

    tool called an Integrated evelopment

    nvironment (I).

    # he latest ersions of Visual Basic are full* o)/ect

    oriented and res'ond to userinitiated eventssuch

    as &ouse clic6s, 6e*stro6es and ti&ers.

    # In Visual tudio, it is conenient to &a6e 'rogra&s

    )* dragging and dro''ing 'redefined o)/ects li6e

    )uttons and te3t)o3es.

  • 8/10/2019 Vb 01edited

    17/37

    1

  • 8/10/2019 Vb 01edited

    18/372009 Pearson Education, Inc. All rights resered.

    1

    !ther +igh-eel -anguages

    #Although hundreds of highleel languages hae)een deelo'ed, onl* a fe" hae achieed )road

    acce'tance.

    # IBM %or'oration deelo'ed ,ortranin the

    &id190s to create scientific and engineering

    a''lications.

    # CO%O!"as deelo'ed in the late 190s )* a

    grou' of co&'uter &anufacturers. %!B!- isused 'ri&aril* for )usiness a''lications that

    reCuire the &ani'ulation of large a&ounts of data.

    19

  • 8/10/2019 Vb 01edited

    19/372009 Pearson Education, Inc. All rights resered.

    19

    !ther +igh-eel -anguages

    # he % language gained "ides'read recognition asa deelo'&ent language for the ?IG o'erating

    s*ste&.

    # %HH "as deelo'ed )* B/arne troustru' in the

    earl* 190s at Bell -a)oratories. %HH 'roidesca'a)ilities for o#ect-oriented programming

    (OOP).

    7 O#ectsare reusa)le soft"are componentsthat

    &odel ite&s in the real "orld.

    7 !)/ectoriented 'rogra&s are easier to understand,

    correct and &odif*.

    20

  • 8/10/2019 Vb 01edited

    20/372009 Pearson Education, Inc. All rights resered.

    20

    !ther +igh-eel -anguages

    # 4eelo'ers use .avato create "e) 'ages "ithd*na&ic content, to )uild largescale 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/. he %

    'rogra&&ing language "as designed

    s'ecificall* for the .E 'latfor&. -i6e VisualBasic, % is o)/ect oriented and has access

    to .EDs li)rar*.

  • 8/10/2019 Vb 01edited

    21/37

    22

  • 8/10/2019 Vb 01edited

    22/372009 Pearson Education, Inc. All rights resered.

    22

    !)/ect echnolog*

    # Procedural programming languagesfocused onactions @er)s rather than o)/ects @nouns.

    # !)/ectoriented languages &ore naturall* reflects the

    "a* in "hich "e 'erceie the "orld.

    # his 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 he 'roduction of soft"are is &ore understanda)le

    )ecause it is )etter organiJed and has fe"er &aintenance

    reCuire&ents.

    25

  • 8/10/2019 Vb 01edited

    23/37

    2009 Pearson Education, Inc. All rights resered.

    25

    !)/ect echnolog*

    # 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)/ectoriented languages.

    28

  • 8/10/2019 Vb 01edited

    24/37

    2009 Pearson Education, Inc. All rights resered.

    28

    he Internet and the $orld $ide $e)

    # In the late 19=0s, ARPA rolled out 'lans tonet"or6 the &ain co&'uter s*ste&s of ARPA

    funded uniersities and research institutions.

    # his )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).

    2

  • 8/10/2019 Vb 01edited

    25/37

    2009 Pearson Education, Inc. All rights resered.

    E3a&'les of Progra&&ing -anguages

    # %: fast, efficient code# Kaa: 'latfor& inde'endence

    # BAI%: ease of use

    # Visual Basic: user interface design using for&s# Perl: te3t &ani'ulation

    2

    2=

  • 8/10/2019 Vb 01edited

    26/37

    2009 Pearson Education, Inc. All rights resered.

    Visual Basic.E s*nta3

    If 3L hen

    MessageBo3.ho"@I a& greater than .

    Else

    MessageBo3.ho" @I a& not greater than .

    End If

    =

    2>

  • 8/10/2019 Vb 01edited

    27/37

    2009 Pearson Education, Inc. All rights resered.

    % *nta3

    if @3L

    N

    MessageBo3.ho" @I a& greater than .O

    else

    N

    MessageBo3.ho" @I a& not greater than .O

    2

  • 8/10/2019 Vb 01edited

    28/37

    2009 Pearson Education, Inc. All rights resered.

    -earning a Progra&&ing -anguage

    #*nta3# tructure

    # Rules

    # Punctuation

    # Resered $ords @6e*"ords eg. If, Else

    # Visual Basic.E is ! case sensitie.

    M*%ase is the sa&e as &*%ase and MQ%AE.

    # %o&&ent lines start "ith an a'ostro'he @

    29

  • 8/10/2019 Vb 01edited

    29/37

    2009 Pearson Education, Inc. All rights resered.

    # 'isual "tudio0

    1232is MicrosoftDs integrateddevelopment environment (I)for creating,

    running and de)ugging a''lications.

    # he I4E allo"s *ou to create a''lications )*

    dragging and dro''ing e3isting )uilding )loc6sinto 'lace.

    # his techniCue is called visual programming.

    # It is a Ra'id A''lication 4eelo'&ent @RA4 tool)ecause it is focused on 'roductiit*.

    Visual tudio 2010 I4E

    50

  • 8/10/2019 Vb 01edited

    30/37

    2009 Pearson Education, Inc. All rights resered.

    Visual tudio 2010 -anguages

    # Visual Basic.E# % @'ronounced %har'

    # K @'ronounced Khar'

    # %HH @'ronounced % 'lus 'lus#AP.E @"e) 'age creation

    51

  • 8/10/2019 Vb 01edited

    31/37

    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.E

    a''lications.

    # %an create different t*'es of a''lications $indo"s A''lications @$indo"s Sor&s or $PS A''lication

    %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.

  • 8/10/2019 Vb 01edited

    32/37

  • 8/10/2019 Vb 01edited

    33/37

  • 8/10/2019 Vb 01edited

    34/37

    2009 Pearson Education, Inc. All rights resered.

    olutions, Pro/ects, and Siles

    5

  • 8/10/2019 Vb 01edited

    35/37

    2009 Pearson Education, Inc. All rights resered.

    %reating a e" Pro/ect

    # elect either File > New Project, "hichcreates a ne" 'ro/ect, or File > OpenProject, "hich o'ens an e3isting 'ro/ect.

    # Sro& the Start Page, under the RecentProjectssection, clic6 the lin6 Create:Project or Open: Project.

    # %lic6 either the New ProjectB$%%o&or theOpen FileB$%%o&.

    5=

  • 8/10/2019 Vb 01edited

    36/37

    2009 Pearson Education, Inc. All rights resered.

    $or6ing $ith a Pro/ect

    # he Solution Explorer"indo" dis'la*s a list ofthe files in a 'ro/ect and the 'ro/ects in a solution.

    # he Properties"indo" dis'la*s an o)/ectDsattri)utes, such as its siJe, color and 'osition. he

    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.

    Propertiesicon O#ect %rowsericon

    $ool#o4icon"olution 4plorericon

    5>

  • 8/10/2019 Vb 01edited

    37/37

    ,igure 1*115Properties"indo" dis'la*ing a 'or#Ds 'ro'erties.

    Objectsname

    (Form1)Objects class

    (System.Windows.Forms.Form)

    Down arrow for selecting Formor control objects

    Items that have beenchanged from their defaultvalues (by the user or by VisualStudio) are listed in bold

    Proerty values(right column)

    Proerties(left column)

    Descrition ofselected roerty

    4esigncategory

    Selected roerty

    !lhabetical icon

    "ategori#ed icon

    "omonent object bo$

    Pro'erties $indo"