《Visual Basic 6.0 课程 学习 计算机.docx》由会员分享,可在线阅读,更多相关《Visual Basic 6.0 课程 学习 计算机.docx(179页珍藏版)》请在课桌文档上搜索。
1、CourseNotesfor:1.earnVisualBasic6.01.ouTylee51998KIDware15600NE8th,SuiteB1-314Bellevue,WA98008(206)721-2556FAX(425)746-4655NoticeThesenotesweredevelopedforthecourse,w1.earnVisualBasic6.0mTheyarenotintendedtobeacompletereferencetoVisualBasic.ConsulttheMicrosoftVisualBasicProgrammersGuideandMicrosoftV
2、isualBasic1.anguageReferenceManualfordetailedreferenceinformation.Thenotesrefertoseveralsoftwareandhardwareproductsbytheirtradenames.Thesereferencesareforinformationalpurposesonlyandalltrademarksarethepropertyoftheirrespectivecompanies.1.ouTyleeCourseInstructor1.earnVisualBasic6.0Contents1.Introduct
3、iontotheVisualBasic1.anguageandEnvironmentPreview1-1CourseObjectives1-1WhatisVisualBasic?1-2VisualBasic6.0versusOtherVersionsofVisualBasic1-316Bitsversus32Bits1-3StructureofaVisualBasicApplication1-4StepsinDevelopingApplication1-4DrawingtheUserInterfaceandSettingProperties1-5Example1-1:StopwatchAppl
4、ication-DrawingControls1-9SettingPropertiesofObjectsatDesignTime1-10SettingPropertiesatRunTime1-11HowNamesAreUsedinObjectEvents1-11Example1-2:StopwatchApplication-SettingProperties1-12Variables1-14VisualBasicDataTypes1-14VariableDeclaration1-14Example1-3:StopwatchApplication-AttachingCode1-18QuickPr
5、imeronSavingVisualBasicApplications1-20Exercise1:CaIendarZTimeDisplay1-21ReviewandPreview2-1ABriefHistoryofBasic2-1VisualBasicStatementsandExpressions2-2VisualBasicOperators2-3VisualBasicFunctions2-4ACloser1.ookattheRndFunction2-5Example2-1:SavingsAccount2-6VisualBasicSymbolicConstants2-10DefiningYo
6、urOwnConstants2-10VisualBasicBranching-IfStatements2-11KeyTrapping2-12Example2-2:SavingsAccount-KeyTrapping2-14SelectCase-AnotherWaytoBranch2-16TheGoToStatement2-17VisualBasic1.ooping2-171. sualBasicCounting2-19Example2-3:SavingsAccount-Decisions2-20Exercise2-1:ComputingaMeanandStandardDeviation2-23
7、Exercise2-2:FlashCardAdditionProblems2-283. ExploringtheVisualBasicToolboxReviewandPreview3-1TheMessageBox3-1ObjectMethods3-3TheFormObject3-4CommandButtons3-51.abelBoxes3-5TextBoxes3-6Example3-1:PasswordValidation3-8CheckBoxes3-11OptionButtons3-11Arrays3-12ControlArrays3-13Frames3-14Example3-2:Pizza
8、Order3-151.istBoxes3-20ComboBoxes3-21Example3-3:FlightPlanner3-23Exercise3:CustomerDatabaseInputScreen3-274. MoreExplorationoftheVisualBasicToolboxReviewandPreview4-1Display1.ayers4-1ShapeToolHorizontalandVerticalScrollBarsExample4-1:TemperatureConversionPictureBoxesImageBoxesQuickExample:Pictureand
9、ImageBoxesDrive1.istBoxDirectory1.istBoxFile1.istBoxSynchronizingtheDrive,Directory,andFile1.istBoxesExample4-2:ImageViewerCommonDialogBoxesOpenCommonDialogBoxQuickExample:TheOpenDialogBoxSaveAsCommonDialogBoxQuickExample:TheSaveAsDialogBoxExercise4:StudentDatabaseInputScreen44444444444444111i11.di1
10、3472445567823242527282911255788267795-5-5-5-5-5-5-5-1-1-1-1-1:5555512572222-55555.CreatingaStand-AloneVisualBasicApplicationReviewandPreviewDesigninganApplicationUsingGeneralSubProceduresinApplicationsCreatingaCodeModuleUsingGeneralFunctionProceduresinApplicationsQuickExample:TemperatureConversionQu
11、ickExample:ImageViewer(Optional)AddingMenustoanApplicationExample5-1:NoteEditorUsingPop-UpMenusAssigningIconstoFormsDesigningYourOwnIconwithIconEditCreatingVisualBasicExecutableFilesExample5-2:NoteEditor-BuildinganExecutableandAttachinganIconUsingtheVisualBasicPackage&DeploymentWizard.Example5-3:Not
12、eEditor-CreatingaDistributionDiskExercise5:USCapitalsQuiz6. Error-Handling,DebuggingandFileInpuVOutputReviewandPreviewErrorTypesRun-TimeErrorTrappingandHandlingGeneralErrorHandlingProcedureExample6-1:SimpleErrorTrappingDebuggingVisualBasicProgramsExample6-2:DebuggingExampleUsingtheDebuggingToolsDebu
13、ggingStrategiesSequentialFilesSequentialFileOutput(Variables)QuickExample:WritingVariablestoSequentialFilesSequentialFileInput(Variables)QuickExample:ReadingVariablesfromSequentialFiles.WritingandReadingTextUsingSequentialFilesRandomAccessFilesUser-DefinedVariablesWritingandReadingRandomAccessFilesU
14、singtheOpenandSaveCommonDialogBoxesExample6-3:NoteEditor-ReadingandSavingTextFilesExercise6-1:InformationTrackingExercise6-2:tRecentFiles1MenuOption1124790167790124569-6-6-6-6-1-1-1-1-1-1-2-2-2-2-2-2-2-3-3:666666666666666-46-1517. GraphicsTechniqueswithVisualBasicReviewandPreviewGraphicsMethodsUsing
15、ColorsMouseEventsExample7-1:BlackboardDragandDropEventsExample7-2:1.etterDisposalTimerToolandDelaysAnimationTechniquesQuickExample:SimpleAnimationQuickExample:AnimationwiththeTimerToolRandomNumbers(Revisited)andGamesRandomlySortingNIntegersExample7-3:One-ButtonedBanditUser-DefinedCoordinatesSimpleFu
16、nctionPlotting(1.ineCharts)1180380345689056811122222223333:77777777777777SimpleBarChartsGraphicsTechniqueswithVisualBasic(continued)Example7-4:1.ineChartandBarChartApplicationExercise7-1:BlackjackExercise7-2:InformationTrackingPlotting8.9.DatabaseAccessandManagementReviewandPreviewDatabaseStructurea
17、ndTerminologyADODataControlBoundDataToolsExample8-1:AccessingtheBooksDatabaseCreatingaVirtualTableQuickExample:FormingaVirtualTableFindingSpecificRecordsExample8-2:,Rolodex,SearchingoftheBooksDatabaseDataManagerExample8-3:PhoneDirectory-CreatingtheDatabase.DatabaseManagementExample8-4:PhoneDirectory
18、-ManagingtheDatabase.CustomDataAwareControlsUsingtheCrystalReportsWriterQuickExample:TabularPhoneDirectory1.istingUsingtheCrystalReportsCustomControlExercise8:HomeInventoryDatabaseDynamic1.ink1.ibrariesandtheWindowsAPIReviewandPreviewDynamic1.ink1.ibraries(D1.1.)AccessingtheWindowsAPIWithD1.1.Timing
19、withD1.1.CallsQuickExample1:UsingGetTickCounttoBuildaStopwatch.QuickExample2:UsingGetTickCounttoImplementaDelayDrawingEllipsesQuickExample3:DrawingEllipsesDrawing1.inesQuickExample4:Drawing1.inesDrawingPolygonsQuickExample5:DrawingPolygonsSoundswithD1.1.Calls-OtherBeeps034445_7771157911347803801258-
20、8-8-8-8-1-1-1-1-1-1-2-2-2-3-3-3-3:888888888888811245677890145-1.-1.-1.-1.-1.-1.-11119999999999-1-1-1-1:9999QuickExample6:AddingBeepstoMessageBoxDisplays.9.Dynamic1.ink1.ibrariesandtheWindowsAPI(continued)MoreElaborateSounds9-16QuickExample7:PlayingWAVFiles9-16PlayingSoundsQuickly9-17QuickExample8:Pl
21、ayingSoundsQuickly9-18FunWithGraphics9-19QuickExample9:BouncingBallWithSound!9-20FlickerFreeAnimation9-22QuickExample10:FlickerFreeAnimation9-23QuickExample11:HorizontallyScrollingBackground9-24ABitofMultimedia9-26QuickExample12:MultimediaSoundandVideo9-26Exercise9:TheOriginalVideoGame-Pong!9-2710.O
22、therVisualBasicTopicsReviewandPreview10-1CustomControls10-1MaskedEditControl10-3ChartControl10-4MultimediaControl10-6RichTextboxControl10-8SliderControl10-9TabbedDialogControl10-12UpDownControl10-13ToolbarControl10-14UsingtheWindowsClipboard10-17PrintingwithVisualBasic10-18MultipleFormVisualBasicApp
23、lications10-21VisualBasicMultipleDocumentInterface(MDI)10-25CreatingaHelpFile10-29ClassSummary10-36Exercise10:TheUltimateApplication10-37Appendix I: VisualBasicSymbolicConstants-1Appendix II: CommonDialogBoxConstants-11.earnVisualBasic6.0(SharewareVersion)KlDware(206)721-2556CourseDescription:1.earn
24、VisualBasic6.0isa10week,self-pacedoverviewoftheVisualBasicprogramminglanguageandenvironment.Uponcompletionofthecourse,youwill:1. UnderstandthebenefitsofusingMicrosoftVisualBasic6.0asanapplicationdevelopmenttool.2. UnderstandtheVisualBasicevent-drivenprogrammingconcepts,terminology,andavailabletools.
25、3. 1.earnthefundamentalsofdesigning,implementing,anddistributingawidevarietyofVisualBasicapplications.1.earnVisualBasic6.0ispresentedusingacombinationofcoursenotes(writteninMicrosoftWordformat)andover60VisualBasicexamplesandapplications.CoursePrerequisites:Tograsptheconceptspresentedin1.earnVisualBa
26、sic6.0,youshouldpossessaworkingknowledgeofWindows95andhavehadsomeexposuretoprogrammingconcepts.Ifyouhaveneverprogrammedacomputerbefore,youllhavetoputinalittlemoreeffort-perhaps,findabookinyourlocallibraryonprogrammingusingQBasicorsomeotherdialectoftheBasiccomputerlanguage.Youwillalsoneedtheabilityto
27、viewandprintdocumentssavedinMicrosoftWordforWindows95format.Thiscanbeaccomplishedinoneoftwoways.Thefirst,andeasiest,isthatyoualreadyhaveMicrosoftWordforWindows95onyourcomputer.Thesecondway,andabitmoredifficult,isthatyoucandownloadWordViewerforWindows95.ThisisafreeMicrosoftproductthatallowsviewingWor
28、ddocuments-itisavailablefordownloadatallthemajorsharewareinternetsites(ZDNet,Download.Com,SoftSeek).Finally,andmostobvious,youneedtohaveMicrosoftVisualBasic6.0,preferablytheProfessionalEdition.1.earnVisualBasic6.0doesnotcovertherudimentsofnavigatinginVisualBasic6.0.Youshouldbefamiliarwiththesimpleta
29、sksofusingthemenus,thetoolbar,resizingwindows,andmovingwindowsaround.VisualBasic6.0providesanexcellenttutorialwithinstructiononsuchtasks.Installing1.earnVisualBasic6.0:Thecoursenotesandcodefor1.earnVisualBasic6.0areincludedinonesingleZIPfile.Useyourfavorite*unzipping,applicationtowriteallfilestoyour
30、computer.Thecourseisincludedinthefolderentitled1.earnVB6-SW.Thisfoldercontainstwootherfolders:VBNotesandVBCode.TheVBNotesfolderincludesallthenotesneededfortheclass.EachfileinthisfolderhasaDOCextensionandisinWordforWindows95format.Thefilesare:StartHere.docContents.docClass1.docClass2.docClass3.docCla
31、ss4.docClass5.doc*Class6.doc*Class7.doc*Class8.doc*Class9.doc*Class10.doc*Appendix1.docAppendixll.docThisfileinWordformatCourseTableofContentsClass1.IntroductiontotheVisualBasic1.anguageandEnvironmentClass2.TheVisualBasic1.anguageClass3.ExploringtheVisualBasicToolboxClass4.MoreExplorationoftheVisual
32、BasicToolboxClass5.CreatingaStand-AloneVisualBasicApplicationClass6.Error-Handling,DebuggingandFilelnputOutputClass7.GraphicsTechniqueswithVisualBasicClass8.DatabaseAccessandManagementClass9.Dynamic1.ink1.ibrariesandtheWindowsAPIClass10.OtherVisualBasicTopicsAppendix I. VisualBasicSymbolicConstantsA
33、ppendix II. CommonDialogBoxConstants(Filesmarkedwitha*arenotincludedinthesharewareversion.)TheVBCodefolderincludesalltheVisualBasicapplicationsdevelopedduringthecourse.TheapplicationsarefurtherdividedintoClassfolders.HowToTaketheCourse:1.earnVisualBasic6.0isaself-pacedcourse.Thesuggestedapproachisto
34、dooneclassaweekfortenweeks.Eachweek,sclassshouldrequireabout4to8hoursofyourtimetograsptheconceptscompletely.Priortodoingaparticularweek,swork,opentheclassnotesfileforthatweekandprintitout.Then,workthroughthenotesatyourownpace.Trytodoeachexampleastheyareencounteredinthenotes.Ifyouneedanyhelp,allsolve
35、dexamplesareincludedintheVBCodefolder.Aftercompletingeachweek,snotes,ahomeworkexerciseisgiven,coveringmanyofthetopicstaughtthatweek.1.iketheexamples,trytoworkthroughthehomeworkexercise,orsomevariationthereof,onyourown.RefertothecompletedprojectintheVBCodefolder,ifnecessary.WhatIfYouHaveQuestions?Iti
36、srecognizedtheremaybetimeswhenyouneedclarificationonsomepointaboutthenotes,examples,orVisualBasic.Wewillgladlyhelp.ThepreferredmethodofrelayingyourquestionstousisviaE-Mail.TheE-Mailaddressis:KIDwarePleaseincludeaclearlydefinedsubjectforallquestionstogetpastourantispammingfilters.Allquestionsshouldbe
37、senttotheattentionof1.ou.WhoProduces1.earnVisualBasic6.0?Thiscoursehasbeendevelopedby1.ouTylee,apartnerinKIDware,aproducerofqualitychildren,seducationalprogramsforover15years.Thecoursenoteshaveevolvedbasedon1.ou,sexperienceinwritingchildren,ssoftwareandinteachingasimilarcourseattheuniversitylevelfor
38、overfouryears.KIDwaremaybecontactedvia:KIDware15600NE8th,SuiteB1-314Bellevue,WA98008(206)721-2556FAX(425)746-4655E-Mail:KIDwareWebSite:SharewareVersionof1.earnVisualBasic6.01.earnVisualBasic6.0isdistributedunderthesharewareconcept.Yougettotrythecoursefree-of-charge.Ifyoufinditdoesntmeetyourneeds,sim
39、pleerasethefilesfromyourcomputer.If,however,youfindthecourseuseful,youareaskedtopayforit.ThecurrentregistrationfeeisUS$19.95(shippingincluded).Thesharewareversionincludesthefirstfourweeksofthecourse.Uponregistration,youwillbesentthecomplete10weekcourse,withallnotesandallapplications.ExaminetheConten
40、ts.docfiletogetaflavorforwhateachweek,sclassentails.Toregisteryourversionof1.earnVisualBasic6.0,simplyfillintheformonthenextpageandmailorFAXittoKIDware.AportionofallregistrationfeesisdonatedtotheFredHutchinsonCancerResearchCenterinSeattle,Washington.REGISTRATIONFORM-1.EARNVISUA1.BASIC6.0VERSION1.01.
41、EARNVISUA1.BASIC6.0isofferedasshareware.Thismeansyougettotrythecoursefreeofcharge.Ifyouusethecourse,however,youareaskedtopayforit.Theregistrationfeeisjust$19.95(add$1.70salestaxifresidentofWashingtonand$2.00postageifoutsidetheUSorCanada).Uponreceiptofyourregistrationfeezyouwillbesentthecomplete10wee
42、kcourse,withallnotesandcode.AportionofthefeeisdonatedtotheFredHutchinsonCancerResearchCenterinSeattle.AllinformationonthisformwillonlybeusedbyKIDware.NameAddressCityStateZipE-MailAddressWheredidyougetyourcopyofthecourse?ICheckIMoneyOrderVISA/MasterCardExpiresCreditCardNumberSignatureSendthisformto:K
43、IDware15600NE8th,SuiteBl-314BellevuezWA98008(206)721-2556FAX(425)746-4655E-Mail:KIDwareO1-121.earnVisualBasic6.01. IntroductiontotheVisualBasic1.anguageandEnvironmentPreview Inthisfirstclass,wewilldoaquickoverviewofhowtobuildanapplicationinVisualBasic.Youlllearnanewvocabulary,anewapproachtoprogrammi
44、ng,andwaystomovearoundintheVisualBasicenvironment.YouwillleavehavingwrittenyourfirstVisualBasicprogram.CourseObjectives=UnderstandthebenefitsofusingMicrosoftVisualBasic6.0forWindowsasanapplicationtool=UnderstandtheVisualBasicevent-drivenprogrammingconcepts,terminology,andavailabletools=1.earnthefund
45、amentalsofdesigning,implementing,anddistributingaVisualBasicapplication=1.earntousetheVisualBasictoolbox=1.earntomodifyobjectpropertiesn1.earnobjectmethods=Usethemenudesignwindow=Understandproperdebugginganderror-handlingproceduresnGainabasicunderstandingofdatabaseaccessandmanagementusingdataboundco
46、ntrolsnObtainanintroductiontoActiveXcontrolsandtheWindowsApplicationProgrammingInterface(API)WhatisVisualBasic? VisualBasicisatoolthatallowsyoutodevelopWindows(GraphicUserInterface-GUI)applications.Theapplicationshaveafamiliarappearancetotheuser. VisualBasicisevent-driven,meaningcoderemainsidleuntilcalledupontorespondtosomeevent(buttonpressing,menuselection,.).VisualBasicisgovernedbyaneventprocessor.Nothinghappensuntilaneventisdetected.Onceaneventisdetected,thecodecorrespondingtothatevent(eventprocedure)