Tải bản đầy đủ (.pdf) (1,339 trang)

An introduction to programming using visual basic 2005, 6th edition (2006)

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (11.9 MB, 1,339 trang )




Tableof

Contents
• Index

AnIntroductiontoProgrammingUsingVisual
Basic®2005,SixthEdition
ByDavidI.Schneider-UniversityofMaryland
Publisher :PrenticeHall
PubDate :March03,2006
PrintISBN-10 :0-13-030654-1
PrintISBN-13 :978-0-13-030654-8
eTextISBN-10 :0-13-186104-2
eTextISBN-13 :978-0-13-186104-6
Pages :752


BasedonthenewestversionofMicrosoft'sVB.NET,thisrevision
ofSchneider'sbest-sellingtextisdesignedforstudentswithno
priorcomputerprogrammingexperience.TheauthorusesVisual
Basic.NETtoexplorethefundamentalsofprogramming,building
astrongfoundationthatwillgivestudentsasustainable
understandingofprogramming.Abroadrangeofexamples,case
studies,exercises,andprogrammingprojectsgivestudents
significanthands-onexperience.A"triedandtrue"text,thisbook
hasbeenconsistentlypraisedbybothstudentsandinstructors.





AnIntroductiontoProgrammingUsingVisual
Basic®2005,SixthEdition
ByDavidI.Schneider-UniversityofMaryland
Publisher :PrenticeHall
PubDate :March03,2006
PrintISBN-10 :0-13-030654-1

PrintISBN-13 :978-0-13-030654-8
Tableof

Contents eTextISBN-10 :0-13-186104-2
eTextISBN-13 :978-0-13-186104-6
• Index
Pages :752







































Copyright
Preface
Acknowledgments
TheCompanionWebsiteforStudentsandInstructors
UsingThisBookforaShortorCondensedCourse
Chapter1.AnIntroductiontoComputersandVisualBasic2005

Section1.1.AnIntroductiontoComputers
Section1.2.UsingWindows
Section1.3.FilesandFolders
Section1.4.AnIntroductiontoVisualBasic2005
Section1.5.BiographicalHistoryofComputing
Chapter2.ProblemSolving
Section2.1.ProgramDevelopmentCycle
Section2.2.ProgrammingTools
Chapter3.FundamentalsofProgramminginVisualBasic
Section3.1.VisualBasicControls
Section3.2.VisualBasicEvents
Section3.3.Numbers
Section3.4.Strings
Section3.5.InputandOutput
Chapter3Summary

xi
xiii
xv
xvi
1
2
4
12
18
21
29
30
32
41

42
60
73
88
105
127












































































Chapter3ProgrammingProjects
Chapter4.GeneralProcedures
Section4.1.SubProcedures,PartI
Section4.2.SubProcedures,PartII
Section4.3.FunctionProcedures
Section4.4.ModularDesign
Chapter4Summary
Chapter4ProgrammingProjects
Chapter5.Decisions
Section5.1.RelationalandLogicalOperators

Section5.2.IfBlocks
Section5.3.SelectCaseBlocks
Section5.4.ACaseStudy:WeeklyPayroll
Chapter5Summary
Chapter5ProgrammingProjects
Chapter6.Repetition
Section6.1.DoLoops
Section6.2.ProcessingListsofDatawithDoLoops
Section6.3.For...NextLoops
Section6.4.ACaseStudy:AnalyzeaLoan
Chapter6Summary
Chapter6ProgrammingProjects
Chapter7.Arrays
Section7.1.CreatingandAccessingArrays
Section7.2.UsingArrays
Section7.3.SomeAdditionalTypesofArrays
Section7.4.SortingandSearching
Section7.5.Two-DimensionalArrays
Section7.6.ACaseStudy:ASophisticatedCashRegister
Chapter7Summary
Chapter7ProgrammingProjects
Chapter8.SequentialFiles
Section8.1.SequentialFiles
Section8.2.UsingSequentialFiles
Section8.3.ACaseStudy:RecordingChecksandDeposits
Chapter8Summary
Chapter8ProgrammingProjects
Chapter9.AdditionalControlsandObjects
Section9.1.ListBoxes,ComboBoxes,andtheFile-Opening


128
131
132
154
169
183
188
188
193
194
201
218
235
243
243
247
248
261
277
291
301
301
307
308
326
341
356
377
392
401

402
411
412
430
442
454
454
461




































Control









































Section9.2.SevenElementaryControls
Section9.3.FourAdditionalObjects
Section9.4.Graphics
Chapter9Summary
Chapter9ProgrammingProjects
Chapter10.DatabaseManagement

Section10.1.AnIntroductiontoDatabases
Section10.2.RelationalDatabasesandSQL
Chapter10Summary
Chapter10ProgrammingProjects
Chapter11.Object-OrientedProgramming
Section11.1.ClassesandObjects
Section11.2.ArraysofObjects;Events;Containment
Section11.3.Inheritance
Chapter11Summary
Chapter11ProgrammingProjects
AppendixA.ANSIValues
AppendixB.HowTo
InvokeandExitVisualBasic
ManagePrograms
UsetheEditor
GetHelp
ManipulateaDialogBox
UseMenus
UtilizetheWindowsEnvironment
DesignaForm
WorkwiththePropertiesofaFormorControl
HowTo:ManageProcedures
ManageWindows
UsethePrinter
UsetheDebugger
AppendixC.ConvertingfromVisualBasic6.0toVisualBasic
2005
Section3.1
Section3.2
Section3.3

Section3.4

462
472
484
496
509
510
517
518
531
548
549
551
552
569
582
601
602
605
607
607
607
609
611
612
613
613
614
615

618
619
619
619
621
621
621
622
622




Section3.5

623




Section4.1
Section4.2

623
623









































































Section4.3
Section6.3
Section7.1
Section7.3
Section8.1
Section9.1
Section9.2
Section9.3
Section9.4
Section10.1
Section10.2
Section11.1
Section11.3
AppendixD.VisualBasicDebuggingTools
TheThreeProgramModes
SteppingthroughaProgram
TheImmediateWindow
TheWatchWindow
TheLocalsWindow
SixWalkthroughs
SteppingthroughanElementaryProgram:Chapter3
SteppingthroughaProgramContainingaGeneralProcedure:
Chapter4
CommunicatingbetweenArgumentsandParameters
SteppingthroughProgramsContainingSelectionStructures:

Chapter5
SteppingthroughaProgramContainingaDoLoop:Chapter6
Answers:ToSelectedOdd-NumberedExercises
Chapter1
Chapter3
Chapter4
Chapter5
Chapter6
Chapter7
Chapter8
Chapter9

623
623
623
624
624
624
624
625
625
625
626
626
626
627
627
628
629
629

630
630
630
632
633
633
635
637
637
638
650
660
668
679
699
706




Chapter10

714



Chapter11

720




InsideFrontCover



Index

InsideFrontCover


Copyright
[Pageiv]
LibraryofCongressCataloging-in-PublicationDataon
File
VicePresidentandEditorialDirector,ECS:MarciaJ.Horton
ExecutiveEditor:TracyDunkelberger
EditorialAssistant:ChristiannaLee
ExecutiveManagingEditor:VinceO'Brien
ManagingEditor:CamilleTrentacoste
ProductionEditor:RoseKernan
DirectorofCreativeServices:PaulBelfanti
CoverDesigner:JonathanBoylan
ManagingEditor,AVManagementandProduction:PatriciaBurns
ArtEditor:XioahongZhu
ManufacturingManager:AlexisHeydt-Long
ManufacturingBuyer:LisaMcDowell
MarketingManager:RobinO'Brien
©2006,2003,1999,1998,1997,1995PearsonEducation,Inc.
PearsonPrenticeHall

PearsonEducation,Inc.
UpperSaddleRiver,NJ07458
Allrightsreserved.Nopartofthisbookmaybereproduced,in
anyformorbyanymeans,withoutpermissioninwritingfrom
thepublisher.
PearsonPrenticeHall™isatrademarkofPearsonEducation,
Inc.


Theauthorandpublisherofthisbookhaveusedtheirbest
effortsinpreparingthisbook.Theseeffortsincludethe
development,research,andtestingofthetheoriesand
programstodeterminetheireffectiveness.Theauthorand
publishermakenowarrantyofanykind,expressedorimplied,
withregardtotheseprogramsorthedocumentationcontained
inthisbook.Theauthorandpublishershallnotbeliableinany
eventforincidentalorconsequentialdamagesinconnection
with,orarisingoutof,thefurnishing,performance,oruseof
theseprograms.
PrintedintheUnitedStatesofAmerica
10987654321
PearsonEducationLtd.,London
PearsonEducationAustraliaPty.Ltd.,Sydney
PearsonEducationSingapore,Pte.Ltd.
PearsonEducationNorthAsiaLtd.,HongKong
PearsonEducationCanada,Inc.,Toronto
PearsonEducacíondeMexico,S.A.deC.V.
PearsonEducationJapan,Tokyo
PearsonEducationMalaysia,Pte.Ltd.
PearsonEducationInc.,UpperSaddleRiver,NewJersey





[Pagexi]


Preface
Sinceitsintroductionin1991,VisualBasichasbeenthemost
widelyusedprogramminglanguageintheworld.Thelatest
incarnationofVisualBasiciscalledVisualBasic2005.Visual
Basicprogrammersareenthusiasticallyembracingthenew
featuresofthelanguage.Likewise,studentslearningtheirfirst
programminglanguagewillfindVisualBasic2005theidealtool
tounderstandthedevelopmentofcomputerprograms.
Myobjectiveswhenwritingthistextwereasfollows:
1. Todevelopfocusedchapters.Ratherthancoveringmany
topicssuperficially,Iconcentrateonimportantsubjectsand
coverthemthoroughly.
2. Touseexamplesandexercisesthatstudentscanappreciate
andwithwhichtheycanrelate,andfeelcomfortable.I
frequentlyuserealdata.Examplesdonothavesomany
embellishmentsthatstudentsaredistractedfromthe
programmingtechniquesillustrated.
3. Toproducecompactlywrittentextthatstudentswillfind
bothreadableandinformative.Themainpointsofeach
topicarediscussedfirst,andthentheperipheraldetailsare
presentedascomments.
4. Toteachgoodprogrammingpracticesthatareinstepwith
modernprogrammingmethodology.Problem-solving

techniquesandstructuredprogrammingarediscussedearly
andusedthroughoutthebook.Thestylefollowsobjectorientedprogrammingprinciples.
5. Toprovideinsightsintothemajorapplicationsof
computers.


[Pagexi(continued)]

UniqueandDistinguishingFeatures
ExercisesforMostSections
Eachsectionthatteachesprogramminghasanexerciseset.
Theexercisesbothreinforcetheunderstandingofthekeyideas
ofthesectionandchallengethestudenttoexploreapplications.
Mostoftheexercisesetsrequirethestudenttotraceprograms,
finderrors,andwriteprograms.TheanswerstoalltheoddnumberedexercisesinChapters1through8andselectedoddnumberedexercisesfromChapters9,10,and11aregivenat
theendofthetext.

PracticeProblems
PracticeProblemsarecarefullyselectedexerciseslocatedatthe
endofasection,justbeforetheexerciseset.Complete
solutionsaregivenfollowingtheexerciseset.Thepractice
problemsoftenfocusonpointsthatarepotentiallyconfusingor
arebestappreciatedafterthestudenthasworkedonthem.The
readershouldseriouslyattemptthepracticeproblemsand
studytheirsolutionsbeforemovingontotheexercises.

ProgrammingProjects
BeginningwithChapter3,chapterscontainprogramming
projects.Theprogrammingprojectsnotonlyreflectthevariety
ofwaysthatcomputersareusedinthebusinesscommunity,

butalsopresentsomegamesandgeneral-interesttopics.The
largenumberandrangeofdifficultyoftheprogramming


projectsprovidetheflexibilitytoadaptthecoursetothe
interestsandabilitiesofthestudents.Someprogramming
projectsinlaterchapterscanbeassignedasend-of-thesemesterprojects.

[Pagexii]

Comments
Extensionsandfinepointsofnewtopicsaredeferredtothe
"Comments"portionattheendofeachsectionsothattheywill
notinterferewiththeflowofthepresentation.

CaseStudies
Eachofthefourcasestudiesfocusesonanimportant
programmingapplication.Theproblemsareanalyzedandthe
programsaredevelopedwithtop-downchartsandpseudocode.
Theprogramscanbefoundonthecompanionwebsiteat
www.prenhall.com/schneider.

ChapterSummaries
InChapters3through11,thekeyresultsarestatedandthe
importanttermsaresummarizedattheendofthechapter.

Procedures
TheearlyintroductionofproceduresinChapter4allows
structuredprogrammingtobeusedinsimplesituationsbefore



beingappliedtocomplexproblems.However,thetextiswritten
sothatthepresentationofprocedureseasilycanbepostponed
untildecisionandrepetitionstructureshavebeenpresented.In
Chapters5and6(andSections7.1and7.2),allprograms
usingproceduresappearattheendsofsectionsandcanbe
deferredoromitted.

Arrays
Arraysareintroducedgentlyintwosections.Thefirstsection
presentsthebasicdefinitionsandavoidsprocedures.The
secondsectionpresentsthetechniquesformanipulatingarrays
andshowshowtopassarraystoprocedures.

HowToAppendix
AppendixBprovidesacompact,step-by-stepreferenceonhow
tocarryoutstandardtasksintheVisualBasicenvironment.

AppendixonDebugging
PlacingofthediscussionofVisualBasic'ssophisticated
debuggerinAppendixDallowstheinstructorflexibilityin
decidingwhentocoverthistopic.

CompanionWebsite
Thecompanionwebsitecontainsalltheexamples,casestudies,
anddatafilesreferencedinthebookaswellasadditional
NetSearchterms,DestinationLinks,onlinestudyguidewith
additionalexercisesandlearningresourcesforstudents.



InstructorResourceCenter
TheInstructorResourceCentercontainssolutionstoevery
exerciseandprogrammingproject,atestitemfileforeach
chapter,PowerPointlectureslides,anddatafilesforallthe
examplesandprogramsfeaturedinthebook.Contactyourlocal
PrenticeHallSalesRepresentativeforinformationonhowto
downloadtheseresources.

[Pagexii(continued)]

What'sNewintheSixthEdition
1. Suggestionsfromstudentsandreviewershavebeen
incorporatedasmuchaspossible.
2. Thereal-lifedataintheexamplesandexerciseshavebeen
updatedandrevised.
3. TheversionofVisualBasichasbeenupgradedfromVB.NET
toVisualBasic2005andtherelevantnewfeaturesofVisual
Basic2005havebeenexplained.
4. Asectionongraphicshasbeenadded
5. Nineprogrammingprojectshavebeenadded.


[Pagexiii]


Acknowledgments
Manytalentedinstructors,students,andprogrammersprovided
helpfulcommentsandconstructivesuggestionsduringthe
preparationofthistext.Fortheircontributionstothequalityof
thefirstfoureditionsofthebookIextendmygratitudetoA.

Abonomah,UniversityofAkron;TimothyBabbitt,Rochester
InstituteofTechnology;WilliamBarnett,NorthwesternState
University;SherryBarriclow,GrandValleyStateUniversity;
RobertBerman,WayneStateUniversity;WilliamBurrows,
UniversityofWashington;DavidChao,SanFranciscoState
University;ChristopherChisolm,UniversityofNebraska,
Omaha;RobertCoil,CincinnatiStateTechnicalandCommunity
College;GaryCornell,UniversityofConnecticut;RonitDancis;
JohnDaPonte,SouthernConnecticutStateUniversity;Ward
Deutschman,Briarcliff;RalphDuffy,NorthSeattleCommunity
College;CharlesFairchild;PatFenton,WestValleyCollege;
DavidFichbohm,GoldenGateUniversity;RobertFritz,American
RiverCollege;MatthewGoddard,NewHampshireTechnical
College;MickieGoodro,CasperCollege;WadeT.Graves,
GraysonCommunityCollege;ChristineGriffin;GaryHaw,MIPS
SoftwareDevelopmentInc.;ShellyHawkins,Microsoft;Tom
Janicki,KentStateUniversity;DanaJohnson,NorthDakota
StateUniversity;DanJoseph,RochesterInstituteof
Technology;DelKimber,ClemsonUniversity;WandaKunkle,
RowanCollege;PaulLecoq,SanFranciscoCommunityCollege;
DavidLeitch,DevryInstitute;DavidLetcher,TheCollegeofNew
Jersey;KieranMathieson,OaklandUniversity;CharlieMiri,
DelawareTech;GeorgeNezlek,DePaulUniversity;RonNotes,
HebrewAcademyofGreaterWashington;MikePaul,Berry
University;T.S.Pennington,MapleWoodsCommunityCollege;
ArlandRichmond,ComputerLearningCenter;DavidRosser,
EssexCountyCollege;ArturoSalazar,SanFranciscoState;
SusannePeterson,Microsoft;JanieSchwark,Microsoft;Mike
Talber,PortlandCommunityCollege;SteveTurek,Devry



InstituteofTechnology,KansasCity;JacVanDeventer,
WashingtonStateUniversity;RandyWeinberg,St.CloudState
University;LaurieWerner,MiamiUniversity;Melinda,White,
SantaFeCommunityCollege;RonaldWilliams,Central
PiedmontCommunityCollege;AmitKalani,CIStemsSolutions
LLC;PritiKalani,MobiEcastCorporation;ChrisPanell,Heald
College;KevinParker,IdahoStateUniversity;TJRacoosin,
rSolutions;andBillTinker,AriesSoftware.
Thecurrenteditionbenefitedgreatlyfromthevaluable
commentsofthefollowingknowledgeablereviewers:
JoeMast,EasternMennoniteUniversity
JoeBrady,UniversityofDelaware
JimMcKeown,DakotaStateUniversity
SydShewchuk,HealdCollege
SaraRushinek,UniversityofMiami
ChakibChraibi,BarryUniversity
Manypeopleareinvolvedinthesuccessfulpublicationofa
book.IwishtothankthededicatedteamatPrenticeHallwhose
supportanddiligencemadethistextbookpossible,especially
MarciaHorton,editor-in-chief,andCamilleTrentacoste,
managingeditor.
IalsoexpressmythankstoMarcLeager,atalented
programmer,whohelpedwiththedevelopmentofthebook,and
providedvaluableinsightsandcarefulproofreading.Iam
gratefultoShaunSzotforhisvaluableproofreading.Production
editor,RoseKernan,andcompositorRebeccaEvansdida
fantasticjobproducingthebookandkeepingitonschedule.
IextendspecialthankstomyeditorTracyDunkelberger.Her



ideasandenthusiasmhelpedimmenselywiththepreparationof
thebook.


[Pagexv]


TheCompanionWebsiteforStudents
andInstructors
[Pagexv(continued)]

HowtoAccesstheCompanionWebsite
Alltheprogramsfromtheexamples,casestudies,TXTfilesfor
theexercises,databasefilesandBMPimagescanbe
downloadedbystudentsandinstructorsat
www.prenhall.com/schneider.

[Pagexv(continued)]

Students
Thecompanionwebsite,locatedat
www.prenhall.com/schneider,containsalltheprogramsfrom
theexamplesandcasestudiessetforthinthistextbook,most
oftheTXTfilesneededfortheexercises,alldatabasesneeded
fortheexercises,andseveralBMP(picture)files.Allthesefiles
arecontainedinthefolder"Programs"inthesubfolders"Ch03",
"Ch04","Ch05",andsoon.Eachchapterfilecontainsa
subfoldernamed"TextfilesforExercises"whichcontainsTXT
filesneededforthatchapter'sexercises.Thefolder"Ch09"has

asubfoldernamed"Pictures"thatcontainstheBMPfiles.The
folder"Ch10"hasasubfoldernamed"MajorDatabases"
containingallthedatabasesneededfortheexercises.
Eachprogramiscontainedinafolderwithanameinthefor
chaptersectionnumber.Forinstance,theprograminChapter3,
Section5,Example2iscontainedinthefolder"3-5-2".Manyof
theprogramsmakeuseofaTXTfileinthesubfolderofthe


program'sfoldernamed"bin."
StudentscanaccessadditionalVisualBasic2005resourcesvia
helpfulNetSearchTermsandDestinationLinkslocatedonthe
companionwebsite.

[Pagexv(continued)]

Instructors
Essentialinstructorresourcesincludingsolutionstothe
exercises,PowerPointlectureslides,alltheexampleprograms
anddatafilesusedbystudentsthroughoutthebook,and
multiple-choiceandtrue/falsequestionsareprovidedonthe
InstructorResourceCenter.ContactyourlocalPrenticeHall
SalesRepresentativetogainaccesstotheIRC.




[Pagexvi]



UsingThisBookforaShortor
CondensedCourse
Thisbookprovidesmorethanenoughmaterialforacomplete
semestercourse.Thetopicsmustbetrimmedforcourses
lastingconsiderablylessthanafullsemester.Thefollowing
syllabusprovidesonepossiblewaytopresentanabbreviated
introductiontoprogramming.

1




3







4





AnIntroductiontoComputersandVisualBasic2005
1.2UsingWindows
1.3FilesandFolders

FundamentalsofProgramminginVisualBasic
3.1VisualBasicControls
3.2VisualBasicEvents
3.3Numbers
3.4Strings
3.5InputandOutput
Procedures
4.1SubProcedures,PartI
4.2SubProcedures,PartII
4.3Functions


5





6





7






9




Decisions
5.1RelationalandLogicalOperators
5.2IfBlocks
5.3SelectCaseBlocks
Repetition
6.1DoLoops
6.2ProcessingListsofDatawithDoLoops
6.3For...NextLoops
Arrays
7.1CreatingandAccessingArrays
7.2UsingArrays(OmitMergingTwoOrderedArrays)
7.3SomeAdditionalTypesofArrays(OmitControlArrays)
AdditionalControlsandObjects
9.1ListBoxes,ComboBoxes,andtheFile-OpeningControl
9.2SevenElementaryControls


[Page1]


×